#import "ViewController.h"
@interface ViewController ()<UIScrollViewDelegate>
{
UIImageView *imageView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
scrollView.contentSize = self.view.bounds.size;
[self.view addSubview:scrollView];
imageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
imageView.image = [UIImage imageNamed:@"scene1.jpg"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
//开启触摸响应
imageView.userInteractionEnabled = YES;
//开启多点触摸
imageView.multipleTouchEnabled = YES;
[scrollView addSubview:imageView];
/*_______________________________________________________________*/
//1⃣️设置缩放范围
//最大倍数
scrollView.maximumZoomScale = 2.0;
//最小倍数
scrollView.minimumZoomScale = 0.5;
//反弹效果
// scrollView.bouncesZoom = NO;
//2⃣️设置代理对象
scrollView.delegate = self;
}
//3⃣️
//返回一个将要缩放的视图
- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return imageView;
}
//缩放时调用
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
NSLog(@"%f",scrollView.zoomScale);
}
//将要开始缩放时
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view{
}
//已经结束缩放时
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale{
}
@end
option + 左键 缩放