人生在世,永远也不该演戏作假 --《异乡人》
这是返回image的方法123456789101112131415/** * 获取屏幕截图 * * @return 返回屏幕截图 */- (UIImage *)fullScreenshots{ UIWindow *window = [UIApplication sharedApplication].keyWindow; UIGraphicsBeginImageContext(window.frame.size); [window.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(image.CGImage,window.frame)]; return image;}
123456789101112131415
/** * 获取屏幕截图 * * @return 返回屏幕截图 */- (UIImage *)fullScreenshots{ UIWindow *window = [UIApplication sharedApplication].keyWindow; UIGraphicsBeginImageContext(window.frame.size); [window.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(image.CGImage,window.frame)]; return image;}
刚学发现一个直接把当前view的界面生成一个view的方法,可用来做动画效果1234567891011-(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; self.navigationController.delegate = self; //生成当前view的快照 UIView *snapShotView = [self.view snapshotViewAfterScreenUpdates:NO]; snapShotView.backgroundColor = [UIColor redColor]; snapShotView.frame = CGRectMake(0, 0, 100, 100); [self.view addSubview:snapShotView]; }
1234567891011
-(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; self.navigationController.delegate = self; //生成当前view的快照 UIView *snapShotView = [self.view snapshotViewAfterScreenUpdates:NO]; snapShotView.backgroundColor = [UIColor redColor]; snapShotView.frame = CGRectMake(0, 0, 100, 100); [self.view addSubview:snapShotView]; }