懒加载
#pragma mark - lazy load
-(UIImageView *)imageView
{
if (!_imageView) {
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100.0f, 100.0f, 100.0f, 100.0f)];
_imageView.backgroundColor = [UIColor redColor];
_imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick)];
[_imageView addGestureRecognizer:tap];
[self.view addSubview:_imageView];
}
return _imageView;
}
-(UIImagePickerController *)imagePickerController
{
if (!_imagePickerController) {
_imagePickerController = [[UIImagePickerController alloc] init];
_imagePickerController.delegate = self;
_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_imagePickerController.allowsEditing = YES;
}
return _imagePickerController;
}
遵循代理<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
#pragma mark - click
-(void)imageClick
{
[self presentViewController:self.imagePickerController animated:YES completion:NULL];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
self.imageView.image = image;
NSLog(@" %@ ",info);
[self dismissViewControllerAnimated:YES completion:NULL];
}
网友评论