刚学习一个获取屏幕快照的方法

这是返回image的方法

/**
 *  获取屏幕截图
 *
 *  @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的方法,可用来做动画效果

-(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];
    
}

你可能感兴趣的:(刚学习一个获取屏幕快照的方法)