This article wants to provide some help to those UI beginners.
I think: Learning ScrollView, may be used in later work is not too much, but it's two sub-categories, I believe the proportion is absolutely great, uitableview and Uicollectionview. As we all know, OC is an object-oriented, high-level language based on C language encapsulation. Object-oriented three major features: encapsulation, inheritance, polymorphism. When it comes to inheritance, subclasses can inherit not only the attributes and methods of the parent class, but also their proxies, so the proxy method of ScrollView, and the settings of each property, can be used in UITableView and Uicollectionview, and people who read the blog can try it out.
To learn any of the controls, you can click into this control to see the contents of its uikit, so that it has all the properties, methods, and proxy methods that you can find. This way can save you a lot of time, you do not need to rote some things, just need to go in to find it.
Talk less, let's take a look at the usage of ScrollView.
viewcontroller.h// scrollview01//// Created by Mac on 15-7-14.// Copyright (c) 2015 Mac. All rights reserved.//#import <uikit/uikit.h>//in the. h file, sign the Uiscrollview proxy method @interface Viewcontroller: Uiviewcontroller<uiscrollviewdelegate> @end
viewcontroller.m//scrollview01////Created by Mac on 15-7-14.//Copyright (c) 2015 Mac. All rights reserved.//#import the usage of "ViewController.h"//scrollview @interface viewcontroller () @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload];//create ScrollView uiscrollview * Scro = [[Uiscrollview alloc]in Itwithframe:cgrectmake (100, 100, 200, 300)]; [Self.view Addsubview:scro]; Scro.delegate = self; Scro.backgroundcolor = [Uicolor Orangecolor]; Set the content size Scro.contentsize = Cgsizemake (400, 400);//used to understand the difference between content size and frame uiimageview *imageview = [[Uiimageview alloc]in Itwithframe:cgrectmake (0, 0, 390, 390)]; UIImage *image = [UIImage imagenamed:@ "20120618101.jpg"]; Imageview.image = image; NSLog (@ "%@", imageview.image); [Scro Addsubview:imageview]; Whether to display horizontal and vertical scrollbars/* scro.showshorizontalscrollindicator = NO; Scro.showsverticalscrollindicator = NO; Whether there is a spring effect scro.bounces = NO; *//Add additional scrolling area Scro.contentinset = UiedgeinsetsMake (30, 30, 30, 30); Set scroll bar style Scro.indicatorstyle = Uiscrollviewindicatorstyleblack; Set Offset Scro.contentoffset = Cgpointmake (-20,-20); Whether the page slip scro.pagingenabled = YES; Whether to turn on scrolling//scro.scrollenabled = NO;} #define The Mark Proxy method//slide when called-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{//NSLog (@ "%@", ScrollView);} When you start dragging, call to let go-(void) scrollviewwillbegindragging: (Uiscrollview *) scrollview{NSLog (@ "sssss%@", ScrollView);} End drag, finger away from screen, decelerate (whether deceleration state)-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL ) decelerate{//decelerate = = YES? NSLog (@ "deceleration"): NSLog (@ "Stop");} Start slow down call-(void) scrollviewwillbegindecelerating: (Uiscrollview *) scrollview{//NSLog (@ "Start slowing down");} Slow Stop call-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView {//NSLog (@ "deceleration stop");} Drag, finger off screen-(void) scrollviewwillenddragging: (Uiscrollview *) ScrollView withvelocity: (cgpoint) Velocity Targetcontentoffset: (inout cgpoint *) targetcontentoffset{//Get coordinates, only makeWith the pointer float tagetx = targetcontentoffset->x;//NSLog (@ "%.2f", Tagetx);}
There may be something missing, or the explanation is not accurate, please note that changes will be made.
ScrollView properties, and Agent method summary