IOS image browser controls zoom in and out, UIScrollView
The image browser uses UIScrollView to set n ScollView UIScrollView attributes in a large ScollView. contentSize and contentoffset indicate the interactive offset of UIScrollView.
The first UIScollView is set to contentSize and contentoffset. The contentSize is set based on the number of images. The contentoffset sets wholeScoll = [[UIScrollView alloc] initWithFrame: CGRectMake (0, 0, myScreenWidth, myScreenHeight)]; wholeScoll. contentOffset = CGPointMake (wholeScoll. frame. size. width * mcurpage, 0); wholeScoll. contentSize = CGSizeMake (myScreenWidth * mImgLocationArr. count, myScreenHeight); // The main code is to add the second layer UIScrollView for (int I = 0; I <mImgLocationArr. count; I ++) {// set imageview UIImageView * imgview = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, myScreenWidth, myScreenHeight)]; imgview. contentMode = browse; // set scrollview preview * singleview = [[Export alloc] initWithFrame: CGRectMake (myScreenWidth * I, 0, myScreenWidth, myScreenHeight)]; [wholeScoll addSubview: singleview]; [singleview addSubview: imgview]; // Add gesture [self addGestureRecognizer];}
Images in the image browser can slide left and right, and can be enlarged by double-clicking, you can click singleTap and double-click doubleTap to pinch pinchGesture and UIScrollView. The singleTap gesture is mainly used to return to the previous page, if the image has been enlarged when the singleTap is triggered, the initial size and coordinates of the image will be initialized. Because singleTap and doubleTap belong to the same gesture class, a gesture conflict will occur. Therefore, [singleTap requireGestureRecognizerToFail: doubleTap]; cancel singleTap ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ Then the climax is coming ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I am a cute splitting line ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ The main operations are doubleTap and pinchGesture, which are two of the most time-consuming questions. First, let's talk about the idea of doubleTap, when doubleTap is executed, it will get a CGPoint tapPoint = [doubletap locationInView: doubletap. view]; then double-click it, enlarge the UIImageView, and move the tapPoint to the center of the screen by setting the contentoffset offset. This is the case where the double-click point is included in the image. In another case, is double-click the point outside the image, and then outside the image and there are four situations: top left, top right, bottom left, bottom right. Enlarge the image, and then display the top left, top right, bottom left, and bottom right sides of the image. Then, you can determine four different situations based on the x and y of the tapPoint.
TapX, tapY is the x of the tapPoint, y imgY is the y value of the image, and imgHeight is the Heightif (tapY myScreenWidth/2) {pointType = custom;} isOutImgView = YES;} else if (tapY> imgY + imgHeight) {// The pointType below = XJAlbumOutImgViewPointLeftDown; if (tapX> myScreenWidth/2) {pointType = XJAlbumOutImgViewPointRightDown;} isOutImgView = YES ;}