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