调用drawViewHierarchyInRect afterScreenUpdates:YES时,iOS8缩放毛刺

我正在将项目从iOS7转换为使用自定义转换的iOS8,并且在完成加载afterScreenUpdates:YES之后需要捕获模式,并且看到整个屏幕缩放一秒钟,然后缩小。 我也看到这发生在部分之间的iOS的Flickr应用程序和Yelp应用程序转换到iOS8上的照片。

  UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, 22.0); [self.view drawViewHierarchyInRect:self.view.frame afterScreenUpdates:YES]; UIGraphicsEndImageContext(); 

添加更大的比例因子有助于强调更多的故障,但是我只是在示例中按下button来调用它。

编辑这似乎发生在iPhone 6和6加上不在5。

规模小故障

示例项目github

你需要它来画屏幕更新后? 因为我正在使用:

 [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO]; 

它似乎在iOS7和iOS8上工作正常。 我想这不是一个定期捕捉图像的很好的解决scheme(如每秒多次),但它似乎适用于一次性模糊。

你必须为6和6提供@ 3x启动图像。 6位的缩放比例为750×1334,6位的图像缩放比例为1242×2208。

即使它看起来像API中的错误,你可以调用drawViewHierarchyInRect与afterScreenUpdates设置为NO来build立快照后屏幕更新,如果你使用这样的cunstruction:

 typedef void (^CompletionHandlerWithId)(id result); -(void)imageContaining:(CGRect)rect afterScreenUpdates:(bool)afterScreenUpdates opaque:(BOOL)opaque completion:(CompletionHandlerWithId)completion { bool success __block; UIImage *snapshotImage __block = nil; CompletionHandler block = ^{ // Create the image UIGraphicsBeginImageContextWithOptions(self.bounds.size, opaque, [[UIScreen mainScreen] scale]); success = [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:NO]; if (success) { snapshotImage = UIGraphicsGetImageFromCurrentImageContext(); CGImageRef imageRef = CGImageCreateWithImageInRect( [snapshotImage CGImage], CGRectMake( snapshotImage.scale*rect.origin.x, snapshotImage.scale*rect.origin.y, snapshotImage.scale*rect.size.width, snapshotImage.scale*rect.size.height)); // or use the UIImage wherever you like snapshotImage = [UIImage imageWithCGImage:imageRef scale:snapshotImage.scale orientation:UIImageOrientationUp]; CGImageRelease(imageRef); } UIGraphicsEndImageContext(); if (completion) { if (! success) { NSLog(@"Error: [UIView drawViewHierarchyInRect] failed on %@", self); (completion)(nil); } else { NSLog(@"Success: [UIView drawViewHierarchyInRect] on %@", self); (completion)(snapshotImage); } } }; if (afterScreenUpdates) [CATransaction setCompletionBlock:^{ (block)(); }]; else (block)(); } 

在运行iOS7的iPad2上运行时,这个bug也存在。

修正:设置afterScreenUpdates:到NO

我的应用程序有一些移动UIButtons,所以我不允许模糊过渡,直到移动停止。 就目前为止我所发现的,YES或NO没有区别。

似乎在iOS9 / XCODE 7版本中得到修复

我find了一个解决scheme来解决这个问题。

我将@ 3x启动图像添加到我的项目。 并select启动屏幕文件到“主”。 这将使应用程序在原始分辨率下运行,在iphone6上运行时的边界更小,但调用drawViewHierarchyInRect时不会出现毛刺。 喜欢这个。

然后,当viewDidLoad时将我的视图缩放到全屏。

 - (void)viewDidLoad{ [super viewDidLoad]; UIScreen *mainScreen = [UIScreen mainScreen]; CGRect tempFrame=mainScreen.bounds; double aspect=tempFrame.size.width/320; self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, aspect, aspect); } 

希望有帮助:)