"iOS Dev-54" Case study: Practice the implementation of proxy mode with Uiscrollview zoom picture function

Source: Internet
Author: User

Case: (Hold down the option key in the simulator and the zoom gesture will appear when you click the mouse)


(1) in VIEWCONTROLLER.M:

--scaling things is a uiscrollview other than scrolling, so things that need to be scaled should be placed first in Uiscrollview, such as the imageview here;

-While we are zooming, scrollview ourselves do not know which control we want to scale, so scrollview need a proxy to tell it, this agent is generally our controller;

--and the controller must obey its protocol to become its agent;

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

--and it's not possible to scale at this point, because the maximum minimum scale of our scrollview is not set, and scaling without boundaries is going to be a big deal.

#import "ViewController.h" @interface Viewcontroller () <uiscrollviewdelegate>//first step, comply with 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 minimum scale for scaling    self.scrollview.maximumzoomscale=2.0;    self.scrollview.minimumzoomscale=0.2;    Set Uiscrollview agent    self.scrollview.delegate=self;//The second step, set yourself as Agent        [Super Viewdidload];    Do any additional setup after loading the view, typically from a nib.} To implement this method, in fact the agent to do is to return the control to zoom to scrollView himself to handle-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) scrollview{    return Self.imageview;} @end


(2) How do I mimic the zoom gesture in the simulator?

By holding down the option key, the zoom gesture appears when you click the mouse and the drag is equivalent to zooming.


(3) Description

Agent, the most important role is to listen. That is, what happens to this control, you can generally notify the agent directly, the agent can know the first time, and the agent can respond accordingly.

Of course, some of the methods in this agreement must be implemented, that is, selective implementation.

"iOS Dev-54" Case study: Practice the implementation of proxy mode with Uiscrollview zoom picture function

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.