iOS show UIImage full screen with zooming (pinch and double tap) enabled

前端 未结 2 1025
走了就别回头了
走了就别回头了 2021-02-03 16:17

I have an UIImage captured from the camera with UIImagePickerController.

Now after the user clicks on it, I\'d like it to show full screen and

2条回答
  •  囚心锁ツ
    2021-02-03 16:25

    i have create this effect for one of my app, dont forget to set delegate of your scrollview.

    code for .h file

    #import 
    
    @interface ImageViewerController : UIViewController
    
    // The scroll view used for zooming.
    @property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
    
    // The image view that displays the image.
    @property (weak, nonatomic) IBOutlet UIImageView *imageView;
    
    // The image that will be shown.
    @property (strong, nonatomic) NSString *imageUrlString;
    
    @end
    

    code for .m

    #import "ImageViewerController.h"
    
    @interface HNImageViewerController ()
    
    - (IBAction)handleSingleTap:(UIButton*)tapGestureRecognizer;
    @end
    
    @implementation ImageViewerController
    
    - (void)viewDidLoad {
    [super viewDidLoad];
    [self.imageView setImage:[UIImage imageNamed:@"placeholder-image"]];
    self.scrollView.delegate=self;
    }
    
    - (BOOL)prefersStatusBarHidden {
    return YES;
    }
    
    #pragma mark - UIScrollViewDelegate methods
    
    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.imageView;
    }
    
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (self.scrollView.zoomScale == self.scrollView.minimumZoomScale) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    }
    
    #pragma mark - Private methods
    
    - (IBAction)handleSingleTap:(UIButton *)tapGestureRecognizer {
    
    [self dismissViewControllerAnimated:YES completion:nil];
    }
    

提交回复
热议问题