標籤:
//
// ViewController.m
// LIBAOZHENG0826
//
// Created by 張豔鋒 on 15/8/26.
// Copyright (c) 2015年 張豔鋒. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
BOOL isOut;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLanch"]) {
NSLog(@"程式首次安裝啟動");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLanch"];
[self makeLaunchView];
}
else{
NSLog(@"程式不是首次安裝啟動");
}
}
-(void)makeLaunchView{
//張豔鋒,引導頁,【四張圖片】
UIScrollView *myScrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,568, 320)];//顯示框大小
myScrollview.tag=121;
myScrollview.backgroundColor=[UIColor redColor];
myScrollview.contentSize=CGSizeMake(568*4, 320);//有效顯示地區
myScrollview.delegate=self;//添加代理
//添加圖片組
for (int i=0; i<4; i++) {
UIImageView *imageview1=[[UIImageView alloc]initWithFrame:CGRectMake(568*i, 0, 568, 320)];//設定圖片顯示大小
NSString *imageName=[NSString stringWithFormat:@"%d.jpg",i];
imageview1.image=[UIImage imageNamed:imageName];
[myScrollview addSubview:imageview1];
}
myScrollview.pagingEnabled=YES;//按頁翻動
[self.view addSubview:myScrollview];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//這裡是在滾動的時候判斷 我滾動到哪張圖片了,如果滾動到了最後一張圖片,那麼
//如果在往下面滑動的話就該進入到主介面了,我這裡利用的是位移量來判斷的,當
//一共五張圖片,所以當圖片全部滑完後 又像後多滑了30 的時候就做下一個動作
if (scrollView.contentOffset.x>4*320+30) {
isOut=YES;//這是我聲明的一個全域變數Bool 類型的,初始值為no,當達到我需求的條件時將值改為yes
}
}
//停止滑動
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//判斷isout為真 就要進入主介面了
if (isOut) {
//這裡添加了一個動畫,(可根據個人喜好)
[UIView animateWithDuration:1.5 animations:^{
scrollView.alpha=0;//讓scrollview 漸層消失
}completion:^(BOOL finished) {
[scrollView removeFromSuperview];//將scrollView移除
// [self gotoMain];//進入主介面
} ];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
IOS引導頁撥動4張圖片最後一張停三秒進入首頁