iOS Note Uikit_uiscrollview

Source: Internet
Author: User

//Through an interface of the system to get is not the first time to start this program if it is to invoke the navigation page if it is not directly into the next view

nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];

if ([Userdefaults objectforkey:@ "firstload"] = = nil)

{

[Userdefaults setbool:no forkey:@ "Firstload"];

Show Navigation page

NSLog (@ "Show navigation page");

View.isfirstload = YES;

}

Else

{

NSLog (@ "Not the first boot no longer appears");

View.isfirstload = NO;

}

-(void) welcome{

if (Self.isfirstload==yes) {

If this is the first time you start the Call Guide page

[Self creatview];

}

}

#pragma mark-Create a scrolling view

-(void) Createuiscrollview

{

//Instantiate scrolling view

Self.scrollview = [[Uiscrollview alloc] init];

//position and size

Self.scrollView.frame = CGRectMake (0, 0,320, 568);

//Set scrolling range of scrolling view

self.scrollView.contentSize =cgsizemake (scroll_w*6, scroll_h);

//Set whether to turn on pagination display

self.scrollView.pagingEnabled = YES;

//Set the drag spring effect

Self.scrollView.bounces =no;

//Set up delegates

self.scrollView.delegate = self;

Add to Parent View

[Self.view AddSubview:self.scrollView];

//Load Pictures

for (int i = 0; i < 6; i++)

{

//uiimageview Show Pictures

Uiimageview *imgview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:[nsstring stringwithformat:@ "%d.jpg", i+ 1]];

//Set each Imgview frame

imgview.frame = CGRectMake (scroll_w*i, 0, Scroll_w, scroll_h);

//Add Imgview to ScrollView

[Self.scrollview Addsubview:imgview];

//Set label display to scroll to which view

Self.titlelabel = [[UILabel alloc]init];

Self.titleLabel.text = [NSString stringwithformat:@ "%d", I];

Self.titleLabel.frame = CGRectMake (0, 24, 320, 30);

Self.titleLabel.backgroundColor = [Uicolor Redcolor];

Self.titleLabel.font = [Uifont systemfontofsize:20];

Self.titleLabel.textAlignment = Nstextalignmentcenter;

Self.titleLabel.layer.cornerRadius = 7;

Self.titleLabel.alpha = 0.5;

[Imgview AddSubview:self.titleLabel];

}

}

#pragma mark-Get the current scrolling view page number

-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView

{

NSLog (@ "%f", scrollview.contentoffset.x);

//As long as greater than 960 can jump

if (Scrollview.contentoffset.x > 960)

{

Jump to the

Trsubviewcontroller *svc = [[Trsubviewcontroller alloc] initwithnibname:@ "Trsubviewcontroller" bundle:nil];

[Self presentviewcontroller:svc animated:yes completion:nil];

}

}

#pragma mark-load view

-(void) viewdidload

{

[Super Viewdidload];

[Self createuiscrollview];

}

#pragma mark-Method of condition monitoring

The user's finger is dragged on the screen in a direction

-(void) scrollviewwillbegindragging: (Uiscrollview *) ScrollView

{

NSLog (@ "Drag in horizontal or vertical direction");

}

This method is called when the user lifts the dragged finger

-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate

{

Tells the value of a bool type whether you need to decelerate before scrolling the last position of the view.

NSLog (@ "Drag to end");

}

Finish zooming

-(void) Scrollviewdidzoom: (Uiscrollview *) ScrollView

{

NSLog (@ "Finish scaling");

}

is when the user's finger has moved away from the screen and the view needs to continue

This method is called when moving. The Contentoffset property is able to get

The position of the last scroll before the user's finger is lifted.

-(void) scrollviewwillbegindecelerating: (Uiscrollview *) ScrollView

{

NSLog (@ "will be stopped when called");

}

Gets a notification when scrolling view stops scrolling. Scrolling views are used

Use the Contentoffset property to reflect the final position of the scrolling view.

-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView

{

NSLog (@ "offset.x =%f", scrollview.contentoffset.x);

}

//will be called when the scrolling view starts scrolling. Read Contentoffset from ScrollView to determine scrolling view scroll to position.

-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView

{

NSLog (@ "offset.x =%f", scrollview.contentoffset.x);

}

-(void) Scrollviewdidscrolltotop: (Uiscrollview *) ScrollView

{

NSLog (@ "Scroll to the head");

}

iOS Note Uikit_uiscrollview

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.