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

前端 未结 2 1026
走了就别回头了
走了就别回头了 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 <UIKit/UIKit.h>
    
    @interface ImageViewerController : UIViewController<UIScrollViewDelegate>
    
    // 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];
    }
    
    0 讨论(0)
  • 2021-02-03 16:43

    This is very easy to implement:

    - (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer;
    

    and then:

    - (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer {    
    recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
    recognizer.scale = 1;    
    } 
    
    0 讨论(0)
提交回复
热议问题