iOS 广告自动转化

来源:互联网 发布:魔力怀旧宠物满档数据 编辑:程序博客网 时间:2024/05/09 01:14


//  ViewController.m

//  ScrollView

//

//  Created by wuweilong on 14/11/8.

//  Copyright (c) 2014 com.wuweilong.cn. All rights reserved.

//

#define HEIGHT ([[UIScreen mainScreen].bounds.size.height])

#define WIDTH  ([[UIScreen mainScreen].bounds.size.width])

#define PAGENUM 5


#import "ViewController.h"


@interface ViewController (){

  

}


@end


@implementation ViewController

@synthesize  imagescrollView,page;

//NSInteger timeCount = 0;

- (void)viewDidLoad {

    [superviewDidLoad];

    

    self.imagescrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(0.0f, 20.0f,320, 90.0f)];

    imagescrollView.contentSize =CGSizeMake(PAGENUM * 320,imagescrollView.frame.size.height);

    imagescrollView.pagingEnabled =YES;

    imagescrollView.showsHorizontalScrollIndicator =NO;

    imagescrollView.delegate =self;

   int i = 0 ;

   for ( i = 0; i < PAGENUM; i++) {

        NSString *fileName = [NSStringstringWithFormat:@"%d.png",i+1];

       UIButton *imageButton = [[UIButtonalloc]initWithFrame:CGRectMake(i * 320.0f,0,320.0f,90.0f)];

        

        [imageButton setBackgroundImage:[UIImageimageNamed:fileName] forState:UIControlStateNormal];

        

        imageButton.tag = 900 + i;

        [imagescrollViewaddSubview:imageButton];

        

    }

    [self.viewaddSubview:self.imagescrollView];

   // [self.view addSubview:self.page];

    

    self.page = [[UIPageControlalloc]init];

   self.page.frame =CGRectMake(100, 50, 100, 20);

    self.page.center =CGPointMake(100, 300);

    self.page.numberOfPages =PAGENUM;

    self.page.currentPage = 0;

    [self.viewaddSubview:self.page];

    [page addTarget:selfaction:@selector(pageTurn:)forControlEvents:UIControlEventValueChanged];

    

    [NSTimer scheduledTimerWithTimeInterval:3 target:selfselector:@selector(pageChange)userInfo:nilrepeats:YES];

  

}

-(void)pageChange{


    timeCount ++;

   if (timeCount ==PAGENUM) {

       timeCount = 0 ;

    }

    self.page.currentPage =timeCount;

    [imagescrollViewscrollRectToVisible:CGRectMake(timeCount *320, 0, 320, 90)animated:YES];


}


-(void)pageTurn:(UIPageControl *)aPageControl{

   int whichPage = aPageControl.currentPage;

    

    [UIView beginAnimations:nilcontext:nil];

    [UIView setAnimationDuration:3.0f];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

    

    [imagescrollViewsetContentOffset:CGPointMake(320.0f *whichPage, 0.0f)];

    

    

    [UIView commitAnimations];


}

- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


0 0
原创粉丝点击