[IOS development-54] Case Study: using the UIScrollView's Zoom image function to practice the specific implementation of the proxy mode,-54 uiscrollview

Source: Internet
Author: User

[IOS development-54] Case Study: using the UIScrollView's Zoom image function to practice the specific implementation of the proxy mode,-54 uiscrollview

Case: (in the simulator, press the option key and click the mouse to see the scaling gesture)


(1) In ViewController. m:

-- Zooming is another function of UIScrollView in addition to scrolling. Therefore, you should first put the zooming in UIScrollView, for example, the imageView here;

-- When scaling, scrollView itself does not know which control we want to scale. Therefore, scrollView requires a proxy to tell it that this proxy is generally our controller;

-- The controller must abide by its Protocol to become its proxy;

-- After the Controller accepts the protocol, it can call this method to tell scrollView which control needs to be scaled;

-- Scaling is not allowed at this time, because the maximum and minimum scaling ratio of the scrollView is not set, and there is no boundary for scaling.

# Import "ViewController. h "@ interface ViewController () <UIScrollViewDelegate> // The first step is to comply with the Protocol @ property (weak, nonatomic) IBOutlet UIScrollView * scrollView; @ property (weak, nonatomic) IBOutlet UIImageView * imageView; @ end @ implementation ViewController-(void) viewDidLoad {// self. scrollView. contentSize = CGSizeMake (892,632); self. scrollView. contentSize = self. imageView. frame. size; // sets the maximum and minimum scale of zooming. scrollView. maximumZoomScale = 2.0; self. scrollView. minimumZoomScale = 0.2; // sets the UIScrollView proxy self. scrollView. delegate = self; // step 2, set yourself as the proxy [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} // to implement this method, the proxy actually needs to return the control to be scaled to the scrollView itself-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView {return self. imageView;} @ end


(2) How do I imitate the scaling gesture in the simulator?

Press and hold the option key, and click the mouse to show a scaling gesture. Dragging is equivalent to scaling.


(3) Description

Proxy, the most important role is listening. That is, the proxy can be directly notified of any changes to this control. The proxy can immediately know and respond accordingly.

Of course, some methods in this protocol must be implemented, that is, selective implementation.


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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.