IOS引導頁撥動4張圖片最後一張停三秒進入首頁

來源:互聯網
上載者:User

標籤:

//

//  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張圖片最後一張停三秒進入首頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.