关于照片的大小缩放

UIScrollView的一些简单常用的方法。

#import "ViewController.h"

@interface ViewController () {
    
    UIScrollView *_scrollView;
    UIImageView *_imageView;
    
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:_scrollView];
    //设置图片
    UIImage *image = [UIImage imageNamed:@"img2"];
    _imageView = [[UIImageView alloc] initWithImage:image];
    [_scrollView addSubview:_imageView];
    //设置照片的大小
    _scrollView.contentSize = image.size;
    //缩放范围 2倍~0.5倍
    _scrollView.maximumZoomScale = 2.0;
    _scrollView.minimumZoomScale = 0.5;
    
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
//你要缩放的范围
    return _imageView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

你可能感兴趣的:(关于照片的大小缩放)