-
Train of thought
Image preview, give priority to basic controls UIImageView, UIButton
Image preview may require different modes, with UIImageView being preferred
typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, UIViewContentModeCenter, UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, } Copy the code
1. Gesture +frame 2. Scrollview zoomScale
Very pleasant decision choice 2, don’t ask why, because I am lazy, can use the system to provide, do not bother
-
serving
- Setting page Properties
@property (nonatomic, strong) UIScrollView *mScroll; @property (nonatomic, strong) UIImageView *imgInfo; Copy the code
- Interface initialization
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); }];Copy the code
MaximumZoomScale and minimumZoomScale represent the scaling degree
- Add a double – click gesture, such as double – click to zoom in, zoom in, zoom out
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandlerTwice)]; tap.numberOfTapsRequired = 2; [self.imgInfo addGestureRecognizer:tap]; Copy the code
- Double click controls scaling directly
- (void)tapHandlerTwice { if (self.mScroll.zoomScale < 2) { [self.mScroll setZoomScale:2]; } else if (self.mScroll.zoomScale < 3) { [self.mScroll setZoomScale:3]; } else { [self.mScroll setZoomScale:1]; }}Copy the code
- UIScrollViewDelegate sets the Zooming View of the ScrollView
#pragma mark - UIScrollViewDelegate - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imgInfo; } Copy the code
-
Game Over