iOS ScrollView to add animation effects, automatic scrolling uiscrollview, using the Nstimer

Source: Internet
Author: User

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];



Related Article

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.