我正在重新编码我们可以在其中拖动图像的主屏幕。
我有一个 setneedsdisplay 方法可以减慢对象的拖动速度。
但是当我在后台线程中调用相同的方法时,问题得到了解决,但应用程序崩溃了。
此外,如果有任何其他选项来录制视频而无需一次又一次地调用 drawRect: 方法?
- (void) drawRect:(CGRect)rect {
NSDate* start = [NSDate date];
CGContextRef context = [self createBitmapContextOfSize:self.frame.size];
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, self.frame.size.height);
CGContextConcatCTM(context, flipVertical);
[self.layer renderInContext:context];
CGImageRef cgImage = CGBitmapContextCreateImage(context);
UIImage* background = [UIImage imageWithCGImage: cgImage];
CGImageRelease(cgImage);
self.currentScreen = background;
if (_recording) {
float millisElapsed = [[NSDate date] timeIntervalSinceDate:startedAt] * 1000.0;
[self writeVideoFrameAtTime:CMTimeMake((int)millisElapsed, 1000)];
}
float processingSeconds = [[NSDate date] timeIntervalSinceDate:start];
delayRemaining = (1.0 / self.frameRate) - processingSeconds;
//CGContextRelease(context);
//redraw at the specified framerate
//[self performSelector:@selector(setNeedsDisplay) withObject:nil afterDelay:delayRemaining > 0.0 ? delayRemaining : 0.01];
[self performSelectorInBackground:@selector(setNeedsDisplay) withObject:nil];
}