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

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

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

#import "UIView+SnapshotView.h"
#import <objc/message.h>

@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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,377评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,245评论 4 61
  • 被有效激励的人生 ,都走在路上 看过一则数据,说过去的十年间,机场书店最畅销的书籍中成功学约占总销量的三成以上。而...
    爱睡觉的邓公子阅读 17,963评论 112 437
  • 2016年6月11日 当生活给予你压力之时,说明你已经学会了准备面对生活中的种种困难并且迎接它的到来 当一次次的失...
    浪子衍阅读 307评论 5 2
  • 作为读写族的老司机,这是第二次做采访作业啦。十四君在我眼中是一个比较神奇的存在,他的爱好广泛,喜欢收藏,好像普通的...
    非宁静无以致远_渊宁阅读 471评论 7 4