1, the use of knowledge points:
In this talk, we want to achieve uiscrollview scaling, to understand and use, Uiscrollview agent, will uiscrollview to scale the elements through the proxy return to the proxy, but also to apply to the Uiscrollview part of the properties, such as: the smallest, Maximum zoom ratio, etc.
2, Scaling principle Notice:
1> Uiscrollview not only scrolls through a large amount of content, but also scales its contents
That is, to complete the zoom function, simply add the content that needs to be scaled to the Uiscrollview
2> Uiscrollview Scaling principle
When the user uses a pinch gesture on Uiscrollview, Uiscrollview sends a message to the agent asking the agent to zoom in on which child control (which piece of content) it is inside.
3> when a user uses a pinch gesture on Uiscrollview, Uiscrollview invokes the proxy's Viewforzoominginscrollview: method, which is the control that the method returns is the one that needs to be scaled
3 Scaling Implementation Steps
1. Set id<uiscrollviewdelegate> delegate proxy object for Uiscrollview
2. Set Minimumzoomscale: Minimum scale reduction
3. Set Maximumzoomscale: Maximum scale magnification
4. Let the proxy object implement the following method to return the view control that needs to be scaled
-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView;
5. Other proxy methods associated with scaling that may be used in peacetime
1> is called when the zoom is complete
-(void) scrollviewwillbeginzooming: (Uiscrollview *) ScrollView Withview: (UIView *) view
Called when 2> is scaling
-(void) Scrollviewdidzoom: (Uiscrollview *) ScrollView
4 Scaling Cases Explained
1> Drag a Uiscrollview control to the controller's view in the storyboard, and let it connect to the controller
2> See VIEWCONTROLLER.M file for a simple Uiscrollview zoom effect
#import "ViewController.h" @interface Viewcontroller () <UIScrollViewDelegate> @property (nonatomic, weak) Iboutlet Uiscrollview *sc; @property (nonatomic, weak) Uiimageview *iv; @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Additional setup after loading the view, typically from a nib. Uiimageview *iv = [[Uiimageview alloc] init]; UIImage *image = [UIImage imagenamed:@ "Minion"]; Iv.image = image; Iv.frame = CGRectMake (0, 0, 240, 240); [Self.sc Addsubview:iv]; SELF.IV = IV; Self.sc.bounces = NO; Uiswitch *SW = [[Uiswitch alloc] init];//[Self.sc ADDSUBVIEW:SW]; To scale, in addition to tell Uisrollview to scale which control, but also tell Uisrollview minimum can be reduced, maximum can put how much self.sc.maximumZoomScale = 2.0; Self.sc.minimumZoomScale = 0.5; Because all of the child controls we added, we have to scale which one we know best//so as long as the controller becomes the agent of Uisrollview, when Uisrollview does not know which control to scale//Uisrollview will call its proxy method , ask the agent exactly which one to scale #warning note: When zooming, two fingers must be within the Uiscrollview range to Self.sc. delegate = self; /* To zoom the picture into two steps 1. Become an agent and tell Uiscrollview which child control to scale by proxy Method 2. Set the maximum child control and the minimum scale */}//because there may be more than one child control in Uisrollview//Then Uisroll The view doesn't know exactly which child control to scale//want to scale, you have to explicitly tell Uisrollview which control to scale #pragma mark-uiscrollviewdelegate// In this method, tell Uisrollview which control to scale-(nullable UIView *) Viewforzoominginscrollview: (nonnull uiscrollview *) scrollview{return SELF.IV;} The process of scaling calls//and Scrollviewdidscroll methods, as long as scaling a little bit will call-(void) Scrollviewdidzoom: (nonnull uiscrollview *) scrollview{ NSLog (@ "%s", __func__);} Call at end of Zoom-(void) scrollviewdidendzooming: (nonnull uiscrollview *) ScrollView Withview: (Nullable UIView *) View Atscale :(cgfloat) scale{NSLog (@ "%s", __func__);} @end
This chapter concludes, and the next chapter explains how to implement pagination controls with Uiscrollview, and the next chapter, Goodbye, ^_^
uiscrollview--Scaling Implementation case (II)