Using recursion to realize the effect of uiscrollview infinite scrolling

Source: Internet
Author: User

Project requirements

The effect of Uiscrollview infinite scrolling is realized by recursion.

On-Machine questions,

#import "ViewController.h"

@interface Viewcontroller () {

Uiscrollview *mainscroll;

BOOL Isfinish;

int x;

}

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

x=0;

Isfinish = YES;

Mainscroll = [[Uiscrollview alloc]init];

Mainscroll.frame = Self.view.bounds;

Mainscroll.contentsize = Cgsizemake (self.view.bounds.size.width*8, self.view.bounds.size.height);

for (int i = 0; i < 8; i++) {

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

Imgview.frame = CGRectMake (self.view.bounds.size.width*i, 0, Self.view.bounds.size.width, Self.view.bounds.size.height);

[Mainscroll Addsubview:imgview];

}

[Self.view Addsubview:mainscroll];

[Self movescroll];

}

The

Start writing code, achieve eight pictures continuously scroll to the last one and then roll back to the first one in reverse order, the loop scrolling does not end.

-(void) Movescroll

{

}

End_code

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

}

@end

Answer:

The

Start writing code, achieve eight pictures continuously scroll to the last one and then roll back to the first one in reverse order, the loop scrolling does not end.

-(void) movescroll{

[Nstimer scheduledtimerwithtimeinterval:0.5 target:self selector: @selector (move) Userinfo:nil Repeats:yes];

}

static int count =-1;

-(void) move

{

x = Mainscroll.contentoffset.x/self.view.bounds.size.width;

if (x = = 0 | | x = = 7) {

Count =-count;

}

x = x +count;

[Mainscroll setcontentoffset:cgpointmake (x*self.view.bounds.size.width, 0)];

}

Using recursion to realize the effect of uiscrollview infinite scrolling

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.