今天在學(xué)習(xí)自定義場(chǎng)景動(dòng)畫的時(shí)候發(fā)現(xiàn)咽斧,貌似在iOS 10中snapshotviewafterscreenupdates
方法失效了。
所以我用runtime的方法交換俱萍,實(shí)現(xiàn)了一下:
#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
這還是我第一次寫文章,應(yīng)該也不算文章吧,算是記錄一下昏名。希望對(duì)大家有點(diǎn)幫助