こんにちはもう一度(私はあなたの以前の貴重な助けに感謝します)。UIView drawRectの偶数および奇数バッファ?
新しい問題:物理シミュレーションを行っていますが、おもちゃバージョンで問題が発生しました。 NSStimer timer
がtick
メソッドを呼び出すたびに、iPhone/Touchのスクリーンにランダムな四角形が描画されます。私はint frameCount
でこれらの呼び出しを索引付けしました。何が見えるのかは、偶数フレーム用のセットと奇数用のセットの2つのセットが徐々に増えていきます。私はわずかに異なる位置に偶数と奇数のカウントで画面にframeCount
を描くことによってこれを確認しました。したがって、フレーム内の画像と同期してカウントが前後に点滅していることがわかります。短縮コードは以下のとおりです。私はあなたが持っている可能性のある提案を感謝します。私には、2つのオフスクリーンバッファが必要であるようです。しかし、私はここで暗闇の中にいます:-)そして、これが真実であっても、私はそれらをマージする方法、または一方を他方にコピーする方法がわかりません。 FooBarの、のUIViewのサブクラスのimplemenationの
#define MAXFRAMES 1000
//関連部品:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
// Start a timer that will call the tick method of this class
// 30 times per second -- slowed way down for diagnostics
timer = [NSTimer scheduledTimerWithTimeInterval:(3.0/1.0)
target:self selector:@selector(tick) userInfo:nil repeats:YES];
frameCount = 0;
self.clearsContextBeforeDrawing = NO;
NSLog(@"frame initialized");
}
return self;
}
- (void)tick
{
// Tell the view that it needs to re-draw itself
if (frameCount < MAXFRAMES) {
[self setNeedsDisplay];
frameCount++;
}
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Draw a random rectangle with CGContextFillRect
// after calling CGContextSetRGBFillColor
// Both called with suitable random parameters
// Draw the frameCount for diagnostic purposes
}
ありがとうございました!これはうまくいった。 –