思路ide
图片预览,优先考虑基础控件UIImageView、UIButtonui
图片预览中可能需设置不一样的mode,优先考虑UIImageViewatom
typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, UIViewContentModeCenter, UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, }
图片放大、缩小的思路:1. 手势+frame 2.scrollview的zoomScale code
很愉快的决定选择2,不要问为何,由于我懒,能用系统提供的,坚定不折腾图片
上菜ip
@property (nonatomic, strong) UIScrollView *mScroll; @property (nonatomic, strong) UIImageView *imgInfo;
self.mScroll = [[UIScrollView alloc] initWithFrame:CGRectZero]; self.mScroll.backgroundColor = [UIColor colorWithHexs:0x3f3f3f]; self.mScroll.maximumZoomScale = 3.0; self.mScroll.minimumZoomScale = 1; self.mScroll.delegate = self; self.mScroll.showsVerticalScrollIndicator = NO; self.mScroll.showsHorizontalScrollIndicator = NO; [self.view addSubview:self.mScroll]; [self.mScroll mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.preView); }];
self.imgInfo = [[UIImageView alloc] initWithFrame:CGRectZero];
self.imgInfo.clipsToBounds = YES;
[self.imgInfo setUserInteractionEnabled:YES];
self.imgInfo.backgroundColor = [UIColor colorWithHexs:0x3f3f3f];
[self.mScroll addSubview:self.imgInfo];
[self.imgInfo mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.mScroll);
make.width.equalTo(self.mScroll);
}];get
其中maximumZoomScale与minimumZoomScale表示可缩放程度 - 顺带加个双击手势,好比双击可放大,再放大,再缩小
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandlerTwice)];
tap.numberOfTapsRequired = 2;
[self.imgInfo addGestureRecognizer:tap];it
- double click直接控制缩放
#pragma mark - UIScrollViewDelegate