IOS_7_scrollView zoom, ios_7_scrollview
Finally:
BeyondViewController. h
//// BeyondViewController. h // 7_scrollView large image display /// Created by beyond on 14-7-24. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <UIKit/UIKit. h> @ interface BeyondViewController: UIViewController-(IBAction) upBtnClick :( id) sender; @ end
BeyondViewController. m
//// BeyondViewController. m // 7_scrollView large image display /// Created by beyond on 14-7-24. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "BeyondViewController. h "@ interface BeyondViewController () <UIScrollViewDelegate> {UIScrollView * _ scrollView; // which internal control is needed for scaling? UIImageView * _ imgView ;} @ end @ implementation BeyondViewController-(void) viewDidLoad {[super viewDidLoad]; // UIImageView // 1, class method to create a control // UIImageView * imgView = [[UIImageView alloc] init]; // 2, control details // NSString * imgName = [NSString stringWithFormat: @ "HD.jpg"]; // imgView. image = [UIImage imageNamed: imgName]; // CGFloat imgW = imgView. image. size. width; // CGFloat imgH = imgView. image. size. height; // imgView. frame = CGRectMake (0, 0, imgW, imgH); // or quickly create a sentence. The code above is _ imgView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "HD.jpg"]; // 1. instantiate UIScrollView _ scrollView = [[UIScrollView alloc] init]; // 2. Set the visible size and content size of the scrollView, and other properties // _ scrollView. frame = CGRectMake (0, 0,320,480); _ scrollView. frame = self. view. bounds; _ scrollView. contentSize = _ imgView. image. size; // the most important part is the rolling area _ scrollView. showsHorizontalScrollIndicator = NO; _ scrollView. showsVerticalScrollIndicator = NO; _ scrollView. bouncesZoom = NO; _ scrollView. bounces = YES; // scrollView. contentOffset is a point, x (left) and y (top). The value is the displacement of the large image drag in the scrollView, compared to scrollView, the upper left corner of the display window // the upper left and lower right are counter-clockwise to the boundary. The returned distance is not allowed. // scrollView. contentInset = UIEdgeInsetsMake (5, 10, 20, 40); // 3, add imgeView to scrollView [_ scrollView addSubview: _ imgView]; // 4, add scrollView to self. view // [self. view addSubview: _ scrollView]; // a small bug is fixed, and the buttons on the interface are completely blocked [self. view insertSubview: _ scrollView atIndex: 0];/* 4. scrollView implements zoom (kneading gesture) in step 1, sets the proxy to the current controller 2, and the proxy to abide by the Protocol <UIScrollViewDelegate> 3. The proxy implements the method viewForZoomingInScrollView in the Protocol, tell the scrollView to zoom in to which control 4 is inside it, and set the maximum and minimum scaling ratio for scrollView */_ scrollView. delegate = self; _ scrollView. min imumzoomscale = 0.3; _ scrollView. maximumZoomScale = 2.0;} // The method in the proxy implementation protocol that tells scrollView which control is to be scaled inside it-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView {return _ imgView;}-(IBAction) upBtnClick :( id) sender {// scrollView. contentOffset is a vertex, x (left) and y (top). The value is the drag displacement of the large image in the scrollView, relative to the upper left corner of the display window of the scrollView [UIView animateWithDuration: 0.3 animations: ^ {// the following three steps are the OC standard code, because OC does not allow users to directly repair the value of the members of the struct attribute in this object, use the temporary struct variable CGPoint offset = _ scrollView in the middle. contentOffset; if (offset. y + 80> = _ scrollView. contentSize. height-_ scrollView. frame. size. height) {return;} offset. y + = 80; _ scrollView. contentOffset = offset;}] ;}@ end
ContentOffset of scrollView
The principle of scrollView is to drag a large image inside it.
Why can't I scale images in IOS? UIScrollView points
To set proxy-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView;
You can scale the view to be scaled as the return value. I just started to learn this. I just checked it online for you. This should be just a proxy method. Others can check UIScrollViewDelegate by themselves.
How can I scale an image during the Sliding Process of android scrollview ????
This has nothing to do with scrollview .. If you want to scale the image, first obtain the width and height of the image, and then set the listener to change the width and height of the image proportionally in XX mode ..