【发布时间】:2017-07-04 10:59:02
【问题描述】:
我正在使用NStimer 方法更新屏幕时截取UIView 的屏幕截图,但Timer 在我截取视图时停止
我经常截取 5 到 8 张截图来捕捉视图上的更新
但计时器停止,无法获得所需的确切屏幕截图
我的代码:
-(void)StartAnmation {
timer= [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(methodToAddImages) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
- (void)methodsave
{
for (int i=0; i<5; i++) {
UIImage *img=[self screenshotimageWithView:self.mainview];
[gifimages addObject:img];
}
}
//截图
- (UIImage ) screenshotimageWithView:(UIView )view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
NSData *miths=UIImagePNGRepresentation(img);
UIImage *imge=[UIImage imageWithData:miths];
UIGraphicsEndImageContext();
return imge;
}
【问题讨论】:
-
添加定时器代码并截图
UIView -
添加一些代码以便我们了解您的问题
-
看看我的更新......
-
我正在通过使用计时器调用方法为图像制作动画,但在我截屏时图像正在停止动画......
标签: ios objective-c screenshot nstimer pause