IOS用戶引導界面示例

jopen 10年前發布 | 39K 次閱讀 IOS iOS開發 移動開發

 //  RootViewController.m

// LessonUIPageControl

// Copyright (c) 2014年 Summer summer2014mht@sina.com. All rights reserved.

import"RootViewController.h"

@interfaceRootViewController ()<UIScrollViewDelegate>

@end

@implementation RootViewController

  • (id)initWithNibName:(NSString )nibNameOrNil bundle:(NSBundle )nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNilbundle:nibBundleOrNil];

if (self) {

   // Custom initialization

}

returnself;

}

  • (void)viewDidLoad

{

[superviewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor = [UIColoryellowColor];

//存儲用戶的偏好設置,存儲在本地,比如:程序是否是第一次加載

NSUserDefaults *userDefaults = [NSUserDefaultsstandardUserDefaults];

if (![userDefaults boolForKey:@"aa"]) {

    [selfsetupFirstLanchView];

    [userDefaultssetBool:YESforKey:@"aa"];

    //立即同步

    [userDefaultssynchronize];

}

}

//創建程序第一次加載要顯示的視圖

  • (void)setupFirstLanchView

{

[selfsetupScrollView];

[selfsetupPageControl];

}

  • (void)setupScrollView

{

UIScrollView *scrollView = [[UIScrollViewalloc]initWithFrame:[UIScreenmainScreen].bounds];

scrollView.delegate =self;

[self.viewaddSubview:scrollView];

//關閉水平方向上的滾動條

scrollView.showsHorizontalScrollIndicator =NO;

//是否可以整屏滑動

scrollView.pagingEnabled =YES;

scrollView.tag =200;

[scrollViewrelease];

scrollView.contentSize =CGSizeMake(320 *6, [UIScreen mainScreen].bounds.size.height);

for (int i = 0; i < 6; i++) {

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(320 * i,0,320, [UIScreenmainScreen].bounds.size.height)];

    imageView.image = [UIImageimageWithContentsOfFile:[[NSBundlemainBundle]pathForResource:[NSStringstringWithFormat:@"v6_guide_%d", i +1]ofType:@"png"]];

    [scrollViewaddSubview:imageView];

    [imageViewrelease];

}

}

  • (void)setupPageControl

{

/**

 *  UIPageControl

 1.表示頁數

 2.表示當前正處于第幾頁

 3.點擊切換頁數

 */

UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(10, [UIScreenmainScreen].bounds.size.height -40, 300, 20)];

pageControl.tag =100;

//設置表示的頁數

pageControl.numberOfPages =6;

//設置選中的頁數

pageControl.currentPage =0;

//設置未選中點的顏色

pageControl.pageIndicatorTintColor = [UIColorgrayColor];

//設置選中點的顏色

pageControl.currentPageIndicatorTintColor = [UIColorblackColor];

//添加響應事件

[pageControladdTarget:selfaction:@selector(handlePageControl:)forControlEvents:UIControlEventValueChanged];

[self.viewaddSubview:pageControl];

[pageControlrelease];

}

  • (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

UIPageControl *pagControl = (UIPageControl *)[self.view viewWithTag:100];

pagControl.currentPage = scrollView.contentOffset.x / 320;

}

  • (void)handlePageControl:(UIPageControl *)pageControl

{

//切換pageControl .對應切換scrollView不同的界面

UIScrollView *scrollView = (UIScrollView *)[self.viewviewWithTag:200];

//

[scrollViewsetContentOffset:CGPointMake(320 * pageControl.currentPage,0)animated:YES];

}

  • (void)didReceiveMemoryWarning

{

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/</pre>

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!