【问题标题】:NSTimer stop while taking screenshot of UiView iOS?NSTimer 在截取 UiView iOS 时停止?
【发布时间】: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


【解决方案1】:

确保在截屏或其他昂贵操作时没有阻塞主线程。

【讨论】:

  • 我已经把我的计时器方法放在主线程中,看看我的更新还是一样
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-30
  • 1970-01-01
  • 2010-11-05
  • 2015-12-08
  • 2011-03-31
  • 1970-01-01
相关资源
最近更新 更多