snapshotViewAfterScreenUpdates的使用

552 阅读1分钟
#import "ViewController.h"

@interface ViewController ()

@property (nonatomic,strong) UIImageView *imageView;

@property (nonatomic,strong) UIView *tempView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    self.imageView = imageView;
    imageView.frame = CGRectMake(100, 100, 100, 100);
    imageView.image = [UIImage imageNamed:@"zrx4.jpg"];
    [self.view addSubview:imageView];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (!self.tempView) {
        self.tempView = [self.imageView snapshotViewAfterScreenUpdates:NO];
        [self.view addSubview:self.tempView];
        self.tempView.frame = CGRectMake(100, 300, 100, 100);
    }
}

@end