bug?在iOS 10中snapshotViewAfterScreenUpdates:方法失效了?

今天在学习自定义场景动画的时候发现,貌似在iOS 10中snapshotviewafterscreenupdates方法失效了。

所以我用runtime的方法交换,实现了一下:

#import "UIView+SnapshotView.h"
#import 

@implementation UIView (SnapshotView)

+ (void)load {
  Method snapshotViewAfterScreenUpdatesMethod =  class_getInstanceMethod(self, @selector(snapshotViewAfterScreenUpdates:));
  Method wwzSnapshotViewAfterScreenUpdatesMethod = class_getInstanceMethod(self, @selector(wwz_snapshotViewAfterScreenUpdates:));
  
  method_exchangeImplementations(snapshotViewAfterScreenUpdatesMethod, wwzSnapshotViewAfterScreenUpdatesMethod);
}

- (UIView *)wwz_snapshotViewAfterScreenUpdates:(BOOL)afterUpdates {
  
  if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10,0,0}]) { // iOS 10
    
    UIGraphicsBeginImageContext(self.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.layer renderInContext:context];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    UIView *newView = [[UIView alloc] initWithFrame:self.frame];
    newView.layer.contents = (id)image.CGImage;
    
    return newView;
  }else { 
    return [self wwz_snapshotViewAfterScreenUpdates:afterUpdates];
  }
}

@end

这还是我第一次写文章,应该也不算文章吧,算是记录一下。希望对大家有点帮助

你可能感兴趣的:(bug?在iOS 10中snapshotViewAfterScreenUpdates:方法失效了?)