实现UIImageView的图片缩放功能,需要结合UIScrollView实现。
示例代码
// 定义缩放比例
CGFloat scaleMini = 1.0;
CGFloat scaleMax = 3.0;
// 主视图 UIScrollView
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:scrollView];
scrollView.pagingEnabled = YES;
scrollView.backgroundColor = [UIColor redColor];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// 图片视图及子视图UIScrollView
//
NSArray *images = @[@"001.jpg", @"002.jpg", @"003.jpg", @"004.jpg"];
//
[images enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
UIImage *image = [UIImage imageNamed:obj];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFit;