#import "MyNewViewController.h"
#import "MainViewController.h"
@interface MyNewViewController ()<UIScrollViewDelegate>
{
? ? NSTimer* timer ;
? ? UIScrollView* scroll ;
? ? intk ;
? ? inti ;
? ? UIPageControl * page ;
}
@end
@implementationMyNewViewController
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? // 新特性界面
? ? // 滾動(dòng)視圖
? ? scroll = [[UIScrollView alloc]initWithFrame:self.view.frame];
? ? scroll.backgroundColor = [UIColor redColor];
? ? // 滾動(dòng)的范圍
? ? scroll.contentSize = CGSizeMake(self.view.frame.size.width * 4 , self.view.frame.size.height);
? ? //? 設(shè)置分頁(yè)
? ? scroll.pagingEnabled = YES ;
? ? // 隱藏水平滾動(dòng)條
? ? scroll.showsHorizontalScrollIndicator = NO ;
? ? // 取消彈簧效果
? ? scroll.bounces=NO;
? ? // 代理
? ? scroll.delegate=self;
? ? // 初始化圖片框
? ? for(i=0;i<4;i++)
? ? {
? ? ? ? UIImageView? * img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]]];
? ? ? ? img.frame = CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
? ? ? ? if(i==3)
? ? ? ? {
? ? ? ? ? ? // 按鈕
? ? ? ? ? ? UIButton* btn = [[UIButtonalloc]initWithFrame:CGRectMake((self.view.frame.size.width-100)/2,600,100,44)];
? ? ? ? ? ? // 按鈕內(nèi)容
? ? ? ? ? ? [btnsetTitle:@"立即體驗(yàn)"forState:UIControlStateNormal];
? ? ? ? ? ? // 設(shè)置圓角
? ? ? ? ? ? btn.layer.cornerRadius=10;
? ? ? ? ? ? btn.layer.masksToBounds=YES;
? ? ? ? ? ? // 設(shè)置邊框
? ? ? ? ? ? btn.layer.borderWidth=2;
? ? ? ? ? ? btn.layer.borderColor= [UIColorcyanColor].CGColor;
? ? ? ? ? ? [btnsetTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
? ? ? ? ? ? // 設(shè)置事件
? ? ? ? ? ? [btnaddTarget:self action:@selector(tiao) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? ? ? // 用戶交互
? ? ? ? ? ? img.userInteractionEnabled = YES ;
? ? ? ? ? ? [imgaddSubview:btn];
? ? ? ? }
? ? ? ? // 圖片加入滾動(dòng)視圖
? ? ? ? [scrolladdSubview:img];
? ? }
? ? // 添加到主視圖
? ? [self.view addSubview:scroll];
? ? // 設(shè)置分頁(yè)控制點(diǎn)
? ? page= [[UIPageControlalloc]initWithFrame:CGRectMake((self.view.frame.size.width-100) /2,650,100,30)];
? ? //分頁(yè)點(diǎn)的個(gè)數(shù)
? ? page.numberOfPages = 4 ;
? ? // 設(shè)置頁(yè)碼的顏色
? ? page.pageIndicatorTintColor = [UIColor greenColor];
? ? // 選中點(diǎn)的顏色
? ? page.currentPageIndicatorTintColor = [UIColor yellowColor];
? ? // 禁用
? ? page.enabled=NO;
? ? // 加入
? ? [self.view addSubview:page];
? ? // 定時(shí)器初始化
? ? timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(DSQ) userInfo:nil repeats:YES];
}
// 時(shí)間控制器的方法
-(void)DSQ
{
? ? // k 的值 等于偏移量?視圖寬的值? ? page.currentPage 默認(rèn)值
? ? k = scroll.contentOffset.x/self.view.frame.size.width ;
? ? //? ? 每隔2.5秒 k加1
? ? k++ ;
? ? // 獲取偏移量
? ? [scroll setContentOffset:CGPointMake(k * self.view.frame.size.width, 0) animated:YES];
? ? if(k>=3)
? ? {
? ? ? ? // 定時(shí)器關(guān)閉
? ? ? ? [timerinvalidate];
//? ? ? ? k = scroll.contentOffset.x/self.view.frame.size.width ;
//? ? ? ? [scroll setContentOffset:CGPointMake(0 * self.view.frame.size.width, 0) animated:YES];
//? ? ? ? [timer fire];
? ? }
}
// 跳轉(zhuǎn)方法
-(void)tiao
{
? ? // 初始化
? ? MainViewController * MainVc = [[MainViewController alloc]init];
? ? //跳轉(zhuǎn)下一個(gè)界面
? ? [self presentViewController:MainVc animated:YES completion:nil];
}
// 當(dāng)視圖滾動(dòng)后? 進(jìn)入此方法
-(void)scrollViewDidScroll:(UIScrollView*)scrollView
{
? ? page.currentPage = scroll.contentOffset.x/self.view.frame.size.width ;
}
@end