Thought: Put a final photo at the top of the entire album, and put a start photo on the last side of the album (for example, there are seven photos in total, h1.jpg-h7.jpg. In order to do the Loop album, now at the top of the add a h7, the last side to add a h1, turned into 9 photos. )。 With a Uiscrollview object to control the slide of the photo, when the slide to the Nineth (the last H1) when the offset into the moment (Width, 0), so it is actually jumping to their own interface, it is generally not visible. When you swipe to the right, when you swipe to the first (at which point the offset is ((0, 0)) The offset becomes (7 * Width, 0) instantaneously, so it moves to the last photo of the original album.
//Macro definition
#define Width Self.view.frame.size.width
#define Height Self.view.frame.size.height
Specific implementation:First step: Initialize a Uiscrollview object and set the basic properties-(void) loadview{
[Super Loadview];
Initialization
_scrollview = [[Uiscrollview alloc]initwithframe:self.view.frame];
_scrollview.contentsize = Cgsizemake (9 * Width, Height);
Offset initial time is (Width, 0)
_scrollview.contentoffset = Cgpointmake (Width, 0);
_scrollview.pagingenabled = YES;
Sign Agreement
_scrollview.delegate = self;
Step two: Set up the picture (add the album to the _scrollview)
Uiimageview *imageviewfront = [[Uiimageview alloc]initwithframe:cgrectmake (0, 0, Width, Height)];
imageviewfront.image = [UIImage imagenamed:@ "h7.jpg"];
[_scrollview Addsubview:imageviewfront];
Make your photos appear in the most appropriate size
Imageviewfront.contentmode = Uiviewcontentmodescaleaspectfit;
[Imageviewfront release];
for (Nsinteger i = 1; I <= 7; i++) {
Uiimageview *imageview = [[Uiimageview alloc]initwithframe:cgrectmake (i * Width, 0, Width, Height)];
Imageview.image = [UIImage imagenamed:[nsstring stringwithformat:@ "h%ld.jpg", I]];
Imageview.contentmode = Uiviewcontentmodescaleaspectfit;
[_scrollview Addsubview:imageview];
[ImageView release];
}
Uiimageview *imageviewlast = [[Uiimageview alloc]initwithframe:cgrectmake (8 * width, 0, width, Height)];
Imageviewlast.image = [UIImage imagenamed:@ "h1.jpg"];
Imageviewlast.contentmode = Uiviewcontentmodescaleaspectfit;
[_scrollview Addsubview:imageviewlast];
[Imageviewlast release];
Step three: Add _scrollview to Self.view
[Self.view Addsubview:_scrollview];
[_scrollview release];
}
The method that is triggered when the view is scrolled after the agreement is signed.
-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{
if (_scrollview.contentoffset.x >= 8 * Width) {
_scrollview.contentoffset = Cgpointmake (Width, 0);
}else if (_scrollview.contentoffset.x < 0) {
_scrollview.contentoffset = Cgpointmake (7 * Width, 0);
}
}
IOS---uiscrollview for album Loops