Reproduced from: http://blog.csdn.net/z343929897/article/details/7974753
In accordance with the general requirements of Zhao, the top of the front page need to add ads, originally thought quite complex, it is very simple
Add a statement to the page controller in the class's declaration file (. h):
@property (Strong, nonatomic) Iboutlet Uipagecontrol *page;
@property (Strong, nonatomic) Iboutlet Uiscrollview *imagescrollview;
Then in the implementation file (. m), add the
@synthesize page;
@synthesize Imagescrollview;
Implements the automatic accessor of the Page object. Rewrite the Viewdidload method as follows
-(void) viewdidload {[Super viewdidload]; This defines the size of the scrolling view, whether it supports paging, whether a horizontal scrolling indicator is displayed, which imagescrollview.contentsize = Cgsizemake (Pagenum * 320.0f,
ImageScrollView.frame.size.height);
imagescrollview.pagingenabled = YES;
Imagescrollview.showshorizontalscrollindicator = NO;
Imagescrollview.delegate = self; This adds a child view for the scrolling view, and in order to add a follow-up operation, the child view I defined here is the key UIButton for (int i = 0; i < pagenum; i++) {NSString * fileName = [N
Sstring stringwithformat:@ "%d.jpg", i+1];
UIButton *imagebutton = [[UIButton alloc] Initwithframe:cgrectmake (i * 320.0f, 0.0f, 320.0f, 218.0f)];
[ImageButton setbackgroundimage:[uiimage Imagenamed:filename] forstate:uicontrolstatenormal];
Imagebutton.tag = 900 + i;
[Imagescrollview Addsubview:imagebutton];
//define Pagecontroller Set total number of pages, current page, define the action to be triggered when the control is manipulated by the user.
0 2page.numberofpages = pagenum;
page.currentpage = 0; [Page addtarget:self action: @selector (Pageturn:) forcontrolevents:uicontroleventValueChanged];
Use the Nstimer implementation to trigger the scrolling action of a scrolling control on a timed basis.
Timecount = 0;
[Nstimer scheduledtimerwithtimeinterval:5 target:self selector: @selector (Scrolltimer) Userinfo:nil Repeats:yes]; }
Add two animation and auto page-flipping functions
Scrolling animation effect
-(void) Pageturn: (Uipagecontrol *) apagecontrol{
int whichpage = apagecontrol.currentpage;
[UIView Beginanimations:nil context:null];
[UIView setanimationduration:0.3f];
[UIView setanimationcurve:uiviewanimationcurveeaseinout];
[Imagescrollview setcontentoffset:cgpointmake (320.0f * whichpage, 0.0f) Animated:yes];
[UIView commitanimations];
}
Timed scrolling
-(void) scrolltimer{
timecount + +;
if (Timecount = = pagenum) {
timecount = 0;
}
Chenyong in this place add self.pageController.currentpage = Timecount; You can change the Pagecon, remember not to add to the bottom of the timecount++
[Imagescrollview scrollrecttovisible:cgrectmake (Timecount * 320.0, 65.0, 320.0, 218.0) Animated:yes];