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