iOS获得截屏效果
2015-06-10 17:12
393 查看
功能:有时候我们做返回上级或者说pop动画的时候,我们需要获取上一个的视图(ViewController)的截图,你可以试一下下面的方法
- (UIImage *)re_screenshot
{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
if ([self respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
NSInvocation* invoc = [NSInvocation invocationWithMethodSignature:
[self methodSignatureForSelector:
@selector(drawViewHierarchyInRect:afterScreenUpdates:)]];
[invoc setTarget:self];
[invoc setSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)];
CGRect arg2 = self.bounds;
BOOL arg3 = YES;
[invoc setArgument:&arg2 atIndex:2];
[invoc setArgument:&arg3 atIndex:3];
[invoc invoke];
} else {
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (UIImage *)re_screenshot
{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
if ([self respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
NSInvocation* invoc = [NSInvocation invocationWithMethodSignature:
[self methodSignatureForSelector:
@selector(drawViewHierarchyInRect:afterScreenUpdates:)]];
[invoc setTarget:self];
[invoc setSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)];
CGRect arg2 = self.bounds;
BOOL arg3 = YES;
[invoc setArgument:&arg2 atIndex:2];
[invoc setArgument:&arg3 atIndex:3];
[invoc invoke];
} else {
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
相关文章推荐
- iOS使用cocoaPods 常见问题,会及时更新
- iOS pragma mark的用法
- iOS pragma mark的用法
- iOS开发系列--通知与消息机制
- iOS开发 之 可穿戴设备 蓝牙4.0 BLE 开发
- 服务器bios调整机器为高性能模式
- iOS 隐藏键盘
- iOS皮肤框架JJSkin介绍
- IOS之OC入门--类方法和对象方法
- 类的声明和实现
- iOS 关于tabelViewcell 显示重叠的问题
- OC中函数和方法的区别
- IOS之OC中的类
- OC入门--基本知识(终端)
- 利用CoreGraphics画小黄人
- 【iOS开发-动画】CAKeyframeAnimation创建动画
- 关于iOS tabelView隐藏多余的cell
- iOS LaunchScreen设置启动图片 启动页停留时间
- ios捕获崩溃
- 【iOS开发-动画】CABasicAnimation实现动画