欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS App引導(dǎo)頁開發(fā)教程

 更新時間:2016年09月30日 09:54:42   作者:u013147734  
這篇文章主要為大家詳細介紹了iOS App引導(dǎo)頁開發(fā)教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下

引導(dǎo)頁功能簡介

方式一:
判斷程序是否首次啟動,如果是將GuidePageViewController作為窗口的根視圖控制器。GuidePageViewController有三個子控件:一個UIScrollView、一個UIPageControl、一個UIButton(默認(rèn)隱藏),UIScrollView有多個UIImageView子控件,當(dāng)滾動到最后一頁UIButton展示,點擊立即體驗然后將窗口的根視圖控制器設(shè)置為UITabBarController;

方式二:
也可以直接將根視圖控制器設(shè)置為UITabBarController, 然后在第一個導(dǎo)航控制器的視圖上展示引導(dǎo)頁視圖,當(dāng)點擊立即體驗再將引導(dǎo)頁視圖隱藏掉即可。

示例代碼

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // 首次啟動應(yīng)用程序時進入到引導(dǎo)頁頁面(暫時沒有判斷,可通過NSUserDefault實現(xiàn))
 self.window.rootViewController = [[GuidePageViewController alloc] init];
 return YES;
}
@end

引導(dǎo)頁視圖控制器GuidePageViewController

#import "GuidePageViewController.h"
#import "ViewController.h"

#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
#define kGuidePageCount 4

@interface GuidePageViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) UIPageControl *pageControl;
@property (weak, nonatomic) UIButton *startAppButton;
@end

@implementation GuidePageViewController

- (void)viewDidLoad {
 [super viewDidLoad];

 // UIScrollView
 UIScrollView *guidePageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
 guidePageScrollView.contentSize = CGSizeMake(kScreenWidth * kGuidePageCount, 0);
 guidePageScrollView.showsHorizontalScrollIndicator = NO;
 guidePageScrollView.pagingEnabled = YES;
 guidePageScrollView.bounces = NO;
 guidePageScrollView.delegate = self;
 for (int i = 0; i < kGuidePageCount; i++) {
  UIImageView *guideImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth * i, 0, kScreenWidth, kScreenHeight)];
  guideImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide-page-%d", i + 1]];
  [guidePageScrollView addSubview:guideImageView];
 }
 [self.view addSubview:guidePageScrollView];

 // UIPageControl(分頁)
 UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake((kScreenWidth - 100) / 2, kScreenHeight- 50, 100, 30)];
 pageControl.numberOfPages = kGuidePageCount;
 pageControl.currentPage = 0;
 pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
 [self.view addSubview:pageControl];
 self.pageControl = pageControl;

 // UIButton(立即體驗)
 UIButton *startAppButton = [UIButton buttonWithType:UIButtonTypeCustom];
 startAppButton.frame = CGRectMake((kScreenWidth - 100) / 2, 550, 100, 40);
 [startAppButton setTitle:@"立即體驗" forState:UIControlStateNormal];
 startAppButton.backgroundColor = [UIColor grayColor];
 [startAppButton addTarget:self action:@selector(startAppAction) forControlEvents:UIControlEventTouchUpInside];
 startAppButton.hidden = YES;
 [self.view addSubview:startAppButton];
 _startAppButton = startAppButton;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
 NSInteger currentPage = scrollView.contentOffset.x / kScreenWidth;
 self.pageControl.currentPage = currentPage;
 if (currentPage == (kGuidePageCount - 1)) {
  self.startAppButton.hidden = NO;
 }
}

- (void)startAppAction {
 // 根視圖控制器一般是UITabBarController,這里簡單實現(xiàn)
 [UIApplication sharedApplication].keyWindow.rootViewController = [[ViewController alloc] init];
}
@end

上述代碼中的圖片名稱是寫死在GuidePageViewController中的,根視圖控制器也是寫死的,如果其他App想要復(fù)用該功能,就要進入該代碼修改這兩哥地方,為了不修改一行代碼就可以使用該功能,可以將這兩個參數(shù)提取出來,初始化該控制器時作為參數(shù)傳遞

封裝示例代碼

初始化時以參數(shù)的形式將圖片和根視圖控制器傳遞給引導(dǎo)頁視圖控制器

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 ViewController *viewController = [[ViewController alloc] init];
 self.window.rootViewController = [[GuidePageViewController alloc] initWithImages:@[@"guide-page-1", @"guide-page-2", @"guide-page-3", @"guide-page-4"] rootViewController:viewController];
 return YES;
}
@end

#import <UIKit/UIKit.h>
@interface GuidePageViewController : UIViewController

- (instancetype)initWithImages:(NSArray *)images rootViewController:(UIViewController *)rootViewController;

@end

在初始化方法中將引導(dǎo)頁圖片和根視圖控制器保存起來,使用self.images.count獲取引導(dǎo)頁數(shù)量,引導(dǎo)頁圖片直接從images數(shù)組中獲取

#import "GuidePageViewController.h"
#import "ViewController.h"

#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)

@interface GuidePageViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) UIPageControl *pageControl;
@property (weak, nonatomic) UIButton *startAppButton;

@property (strong, nonatomic) NSArray *images;
@property (strong, nonatomic) UIViewController *rootViewController;
@end

@implementation GuidePageViewController

- (instancetype)initWithImages:(NSArray *)images rootViewController:(UIViewController *)rootViewController {
 if (self = [super init]) {
  _images = images;
  _rootViewController = rootViewController;
 }

 return self;
}

- (void)viewDidLoad {
 [super viewDidLoad];

 // UIScrollView
 UIScrollView *guidePageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
 guidePageScrollView.contentSize = CGSizeMake(kScreenWidth * self.images.count, 0);
 guidePageScrollView.showsHorizontalScrollIndicator = NO;
 guidePageScrollView.pagingEnabled = YES;
 guidePageScrollView.bounces = NO;
 guidePageScrollView.delegate = self;
 for (int i = 0; i < self.images.count; i++) {
  UIImageView *guideImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth * i, 0, kScreenWidth, kScreenHeight)];
  guideImageView.image = [UIImage imageNamed:self.images[i]];
  [guidePageScrollView addSubview:guideImageView];
 }
 [self.view addSubview:guidePageScrollView];

 // UIPageControl
 UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake((kScreenWidth - 100) / 2, kScreenHeight- 50, 100, 30)];
 pageControl.numberOfPages = self.images.count;
 pageControl.currentPage = 0;
 pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
 [self.view addSubview:pageControl];
 self.pageControl = pageControl;

 UIButton *startAppButton = [UIButton buttonWithType:UIButtonTypeCustom];
 startAppButton.frame = CGRectMake((kScreenWidth - 100) / 2, 550, 100, 40);
 [startAppButton setTitle:@"立即體驗" forState:UIControlStateNormal];
 startAppButton.backgroundColor = [UIColor grayColor];
 [startAppButton addTarget:self action:@selector(startAppAction) forControlEvents:UIControlEventTouchUpInside];
 startAppButton.hidden = YES;
 [self.view addSubview:startAppButton];
 _startAppButton = startAppButton;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
 NSInteger currentPage = scrollView.contentOffset.x / kScreenWidth;
 self.pageControl.currentPage = currentPage;
 if (currentPage == (self.images.count - 1)) {
  self.startAppButton.hidden = NO;
 }
}


- (void)startAppAction {
 [UIApplication sharedApplication].keyWindow.rootViewController = self.rootViewController;
}
@end

終極解決方案

直接使用github上的開源功能即可GitHub引導(dǎo)頁

1、創(chuàng)建出所有引導(dǎo)頁EAIntroPage
2、創(chuàng)建引導(dǎo)頁視圖EAIntroView 并設(shè)置代理
3、顯示引導(dǎo)頁視圖

創(chuàng)建出所有引導(dǎo)頁EAIntroPage

// basic: 標(biāo)題和描述
EAIntroPage *page1 = [EAIntroPage page];
page1.title = @"Hello world";
page1.desc = sampleDescription1;

// custom
EAIntroPage *page2 = [EAIntroPage page];
page2.title = @"This is page 2";
page2.titleFont = [UIFont fontWithName:@"Georgia-BoldItalic" size:20];
page2.titlePositionY = 220;
page2.desc = sampleDescription2;
page2.descFont = [UIFont fontWithName:@"Georgia-Italic" size:18];
page2.descPositionY = 200;
page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title2"]];
page2.titleIconPositionY = 100;

// custom view from nib
EAIntroPage *page3 = [EAIntroPage pageWithCustomViewFromNibNamed:@"IntroPage"];
page3.bgImage = [UIImage imageNamed:@"bg2"];

創(chuàng)建引導(dǎo)頁視圖EAIntroView 并設(shè)置代理
EAIntroView *intro = [[EAIntroView alloc] initWithFrame:self.view.bounds andPages:@[page1,page2,page3,page4]];
intro.delegate=self;

顯示引導(dǎo)頁視圖
[intro showInView:self.view animateDuration:0.0];

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • IOS中的webView加載HTML

    IOS中的webView加載HTML

    在日常開發(fā)中,我們?yōu)榱诵蕰玫胶芏嗪芏嗟腤ebView,比如在做某個明細頁面的時候我們返回給你的可能是一個html字符串,我們就需要將當(dāng)前字符串展示到webView上面,所以我們對HTML標(biāo)簽需要有一定的認(rèn)識,下面我們來一起用html標(biāo)簽和JS寫一個打地鼠游戲
    2016-02-02
  • iOS 頁面滑動與標(biāo)題切換顏色漸變的聯(lián)動效果實例

    iOS 頁面滑動與標(biāo)題切換顏色漸變的聯(lián)動效果實例

    本篇文章主要介紹了iOS 頁面滑動與標(biāo)題切換顏色漸變的聯(lián)動效果實例,具有一定的參考價值,有興趣的可以了解一下。
    2017-04-04
  • iOS實現(xiàn)帶有縮放效果的自動輪播圖

    iOS實現(xiàn)帶有縮放效果的自動輪播圖

    這篇文章主要為大家詳細介紹了iOS帶有縮放效果的自動輪播圖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • ios使用AVFoundation讀取二維碼的方法

    ios使用AVFoundation讀取二維碼的方法

    這篇文章主要介紹了ios使用AVFoundation讀取二維碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • iOS實現(xiàn)滑動弧形菜單的思路與方法

    iOS實現(xiàn)滑動弧形菜單的思路與方法

    這篇文章主要給大家介紹了利用iOS實現(xiàn)滑動弧形菜單的思路與方法,實現(xiàn)后的效果非常不錯,非常適合大家在開發(fā)中使用,文末給出了封裝源碼下載的地址供大家下載學(xué)習(xí),需要的朋友可以參考,下面來一起看看吧。
    2017-05-05
  • iOS實現(xiàn)PDF文件瀏覽功能

    iOS實現(xiàn)PDF文件瀏覽功能

    這篇文章主要為大家詳細介紹了iOS實現(xiàn)PDF文件瀏覽功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • IOS 開發(fā)之?dāng)?shù)據(jù)存儲writeToFile的應(yīng)用實例

    IOS 開發(fā)之?dāng)?shù)據(jù)存儲writeToFile的應(yīng)用實例

    這篇文章主要介紹了IOS 開發(fā)之?dāng)?shù)據(jù)存儲writeToFile的應(yīng)用實例的相關(guān)資料,這里提供實例幫助大家實現(xiàn)這樣的功能,需要的朋友可以參考下
    2017-09-09
  • IOS開發(fā)之路--C語言數(shù)組和字符串

    IOS開發(fā)之路--C語言數(shù)組和字符串

    數(shù)組在C語言中有著特殊的地位,它有很多特性,例如它的存儲是連續(xù)的,數(shù)組的名稱就是數(shù)組的地址等。而在C語言中是沒有String類型的,那么如果要表示一個字符串,就必須使用字符串?dāng)?shù)組
    2014-08-08
  • ios開發(fā) try-catch引起的野指針問題排查

    ios開發(fā) try-catch引起的野指針問題排查

    這篇文章主要為大家介紹了ios開發(fā) try-catch引起的野指針問題排查,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • iOS路由(MGJRouter)的實現(xiàn)

    iOS路由(MGJRouter)的實現(xiàn)

    這篇文章主要介紹了iOS路由(MGJRouter)的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09

最新評論