Objective-c:uiscrollview Controls and Uipagecontrol controls

Source: Internet
Author: User

Uiscrollview Controls and Uipagecontrol controls: Uiscrollview is used to display more than one screen, content that goes beyond the screen can be viewed by swiping, and of course Uipagecontrol can be paged. Uiscrollview tend to be used with Uipagecontrol, when Uiscrollview paging, Uipagecontrol corresponding points will also change, picture rollover, and vice versa.First,UiscrollviewCommon Properties:@interface Uiscrollview:uiview <NSCoding> {

@property (nonatomic) cgpoint contentoffset;// Uiscrollview the current scrolling position

@property (nonatomic) cgsize contentsize; sets the scrolling range of the Uiscrollview (scroll chart size)

@property (nonatomic) uiedgeinsets contentinset;// This property can increase the scrolling range in four weeks (that is, add or decrease the surrounding blank section)

@property (nonatomic,assign) id<uiscrollviewdelegate> delegate;// Agent for scrolling view

@property (nonatomic,getter=isdirectionallockenabled) BOOL directionallockenabled;// controls are scrolled only in one Direction

@property (nonatomic) BOOL bounces; does it have a spring effect?

@property (nonatomic) BOOL  alwaysbouncevertical; set the spring effect in the vertical direction

@property (nonatomic) BOOL alwaysbouncehorizontal;// set Spring effect in horizontal direction

@property (nonatomic,getter=ispagingenabled) BOOL pagingenabled;// controls whether the control is full-page flipping

@property (nonatomic,getter=isscrollenabled) BOOL scrollenabled; Whether you can scroll

@property (nonatomic) BOOL showshorizontalscrollindicator;// whether to display scroll bars in horizontal direction

@property (nonatomic) BOOL showsverticalscrollindicator; whether to display scroll bars in the vertical direction

@property (nonatomic) uiedgeinsets  scrollindicatorinsets; Set Scrolling Range

@property (nonatomic) Uiscrollviewindicatorstyle Indicatorstyle; Set scroll bar style

@property (nonatomic) cgfloat decelerationrate;// Set the deceleration rate after finger release

@property (nonatomic) cgfloat zoomscale// indent ratio

@property (nonatomic) BOOL bounceszoom// whether the given spring ratio is achieved

@property (nonatomic) BOOL scrollstotop// Whether you can scroll to the top

} @end

Uiscrollview Common methods:

-(void) Setcontentoffset: (Cgpoint) Contentoffset animated: (BOOL) animated; set a new offset for animation at a constant speed

-(void) scrollRectToVisible: (cgrect) Rect animated: (BOOL) animated; setting the area defined by RECT is only visible within the scrolling view

-(void) flashscrollindicators; Flash the scroll bar to indicate if there is anything scrollable

Second,Uiscrollview gesture Scalingset id<uiscrollviewdelegate> delegate proxy object for Uiscrollviewset Minimumzoomscale: Minimum scale to zoom outset Maximumzoomscale: Maximum scale magnificationlet the proxy object implement the following method to return the view control that needs to be scaled

-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView

the common methods associated with scaling are also

-(void) Scrollviewdidzoom: (Uiscrollview *) ScrollView is being scaled when calling the

-(void) scrollviewdidendzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Atscale: (float) scale Call when zoom is complete

Three, Uipagecontrol effect of the page

Set Pagingenabled=yes, Uiscrollview will be divided into multiple separate pages, the user's scrolling experience has become a page flipping generally with uipagecontrol enhance the paging effectUipagecontrol Common Properties:Nsinteger numberofpages: Total PagesNsinteger currentpage: The current page numberBOOL hidesforsinglepage: Do you want to hide the view when there is only one page?

@property (nonatomic,retain) uicolor *pageindicatortintcolor; Set Controller page point color

@property (nonatomic,retain) uicolor *currentpageindicatortintcolor; Sets the color of the current page point of the controller

Monitor Uipagecontrol page Changes:

Add Listener

[Pagecontrol addtarget:self Action: @selector (Pagechange:)

Forcontrolevents:uicontroleventvaluechanged];

Monitoring methods

-(void) Pagechange: (Uipagecontrol *) Pagecontrol

{

}

Four, Uiscrollview Scrolling view to implement the protocol:Uiscrollviewdelegate

@protocol uiscrollviewdelegate<nsobject>

@optional

-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView;//Called when scrolling operation is being performed on a scroll view

-(void) Scrollviewdidzoom: (Uiscrollview *) ScrollView; called when performing a zoom operation on a scrolling view

-(void) scrollviewwillbegindragging: (Uiscrollview *) ScrollView; Called when the drag of the execution scrolling view starts

-(void) scrollviewwillenddragging: (Uiscrollview *) ScrollView withvelocity: (cgpoint) Velocity Targetcontentoffset: (inout cgpoint *) Targetcontentoffset; //Execute scrolling View when dragging ends call

-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate;// Called when the drag at the end of a scrolling view is executed (slowing down)

-(void) scrollviewwillbegindecelerating: (Uiscrollview *) ScrollView; //Perform a scrolling view when the slow start is called

-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView; //Perform scrolling view at end of deceleration call

-(void) Scrollviewdidendscrollinganimation: (Uiscrollview *) ScrollView; //Scroll view animation ends when called

-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) scrollview;// Returns a new view when performing a scrolling view indent

-(void) scrollviewwillbeginzooming: (Uiscrollview *) ScrollView Withview: (UIView *) view; called when the scroll view is indented to start

-(void) scrollviewdidendzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Atscale: (cgfloat) scale; called when the scroll view is indented at the end

-(BOOL) Scrollviewshouldscrolltotop: (Uiscrollview *) ScrollView; //Scroll the view to scroll to the top

-(void) Scrollviewdidscrolltotop: (Uiscrollview *) ScrollView; //Scroll view to scroll to the top when called

@end

code Sample parsing:One, single photo case: (1)

Set ImageView, get picture resources

UIImage *img = [UIImage imagenamed:@ "landscape.jpg"];

Self.imageview = [[Uiimageview alloc]init];

[Self.imageview setimage:img];

Self.imageview.contentMode = Uiviewcontentmodescaleaspectfit; //Prevent images from distorting in the process of transformation

Self.imageview.frame = CGRectMake (0, 0, img.size.width, img.size.height);

Set ScrollView (position and size i.e. origin.x, ORIGIN.Y, Size.width, Size.Height)

Self.scrollview.contentSize = img.size; //Set the range size of the content in the scrolling view directly to the size of the picture

Self.scrollview.contentOffset = Cgpointzero; //Default origin.x = 0,ORGIN.Y = 0

Spring effect (the so-called spring effect is that regardless of the picture is dragged into the scroll diagram where the release will return to the original position)

Self.scrollview.bounces = NO;

Add four margin (equivalent to the frame portion)

Self.scrollview.contentInset = Uiedgeinsetsmake (10, 10, 10, 10);

Scrolling effect (if the picture is too large, you can drag and drop to see other parts)

self.scrollview.scrollEnabled = YES;

scroll bar settings (similar to sliders, sliding up or down, or left and right sliding)

Self.scrollview.showsHorizontalScrollIndicator = no;//Horizontal Direction

Self.scrollview.showsVerticalScrollIndicator = NO; Vertical direction

Set the style of the scroll bar

Self.scrollview.indicatorStyle = Uiscrollviewindicatorstyleblack;

Add a view to a scrolling view

[Self.scrollview AddSubview:self.imageview];

Set the view to the last face of the scrolling view (if you add other controls such as UIButton on the scrolling view, this way you can avoid the button control being obscured by the picture)

[Self.scrollview SendSubviewToBack:self.imageview];

//Add button events to scroll the picture

-(Ibaction) buttonclicked: (UIButton *) Sender

{

Cgpoint point = Self.scrollview.contentOffset;

Self.scrollview.contentOffset = Cgpointmake (point.x+20, POINT.Y);

}

Second, the picture rotation player case:

Objective-c:uiscrollview Controls and Uipagecontrol controls

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.