Uiview 使用计时器调用drawViewHierarchyInRect时挂起

Uiview 使用计时器调用drawViewHierarchyInRect时挂起,uiview,uikit,ios7,Uiview,Uikit,Ios7,应该使用此方法来创建UIView快照 + (UIImage *)screenshotWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0f); if( [view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)] ) { // LP: i

应该使用此方法来创建UIView快照

+ (UIImage *)screenshotWithView:(UIView *)view {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0f);
    if( [view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)] ) { // LP: iOS 7 only
        [view drawViewHierarchyInRect:view.bounds
                   afterScreenUpdates:[view superview]?NO:YES];
    } else {
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    }
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}
在一段时间内执行此方法时,我们可以这样说

runTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0f/30
                                                target:self
                                              selector:@selector(sendScreen)
                                              userInfo:nil

                                       repeats:repeat];
应用程序变得越来越慢。UI不会冻结,快照也会拍摄,但性能会显著降低

这正是苹果在iOS7的新UI方法中所没有的建议:

使用经典时

 [view.layer renderInContext:UIGraphicsGetCurrentContext()];
一切正常,但我们当然已经知道了

试一试失败

- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates

我没有看到drawViewHierarchyInRect:AfterScreenuUpdate的性能改进:事实上,我有时看到它速度较慢。