iOS 引導頁

來源:互聯網
上載者:User

iOS 引導頁

/

// ADo_ViewController.m

// ADo_GuideView

//

// Created by dwx on 15/5/1.

// Copyright (c) 2015年 Nododo. All rights reserved.

//

 

#import "ADo_ViewController.h"

//#import "ADo_SecViewController.h"

#import "UIView+Extension.h"

#import "homeViewController.h"

#define screenW self.view.frame.size.width

#define screenH self.view.frame.size.height

#define pageCount 5

#define picH 2330 / 2

#define padding 200

#define topPicH 70

#define topPicW 112

#define btnH 100

#define btnW 140

@interface ADo_ViewController ()

/**

* 底部滾動圖片

*/

@property (nonatomic,strong)UIScrollView *guideView;

/**

* 球形圖片

*/

@property (nonatomic,strong)UIImageView *picView;

/**

* 牌型滾動

*/

@property (nonatomic,strong)UIImageView *paiView;

/**

* 指示

*/

@property (nonatomic,strong)UIPageControl *pageControl;

/**

* 頂部圖片滾動

*/

@property (nonatomic,strong)UIScrollView *topView;

@end

 

@implementation ADo_ViewController

 

- (void)viewDidLoad {

[super viewDidLoad];

/**

背景圖片

*/

UIImageView *backView = [[UIImageView alloc]initWithFrame:self.view.frame];

backView.image = [UIImage imageNamed:@"page_bg_35"];

[self.view addSubview:backView];

 

/**

滾動 輔助作用

*/

UIScrollView *ado_guideView = [[UIScrollView alloc] initWithFrame:self.view.frame];

ado_guideView.contentSize = CGSizeMake(screenW * pageCount, screenH);

ado_guideView.bounces = NO;

ado_guideView.pagingEnabled = YES;

ado_guideView.delegate = self;

ado_guideView.showsHorizontalScrollIndicator = NO;

 

/**

滾動球

 

*/

UIImageView *picView = [[UIImageView alloc] init];

picView.width = picH ;

picView.height = picH;

picView.centerX = screenW / 2;

picView.centerY = screenH + padding;

#warning 設定錨點是個坑

picView.layer.anchorPoint = CGPointMake(0.5, 0.5);

picView.image = [UIImage imageNamed:@"guider_qiu_35"];

 

/**

滾動牌

*/

UIImageView *paiView = [[UIImageView alloc] init];

paiView.width = picH;

paiView.height = picH;

paiView.centerX = screenW / 2 ;

paiView.centerY = screenH + padding;

paiView.layer.anchorPoint = CGPointMake(0.5, 0.5);

paiView.image = [UIImage imageNamed:@"guider_pai_35"];

 

/**

指標

*/

UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(screenW / 2 - 50, screenH - 20, 100, 20)];

pageControl.numberOfPages = 5;

pageControl.currentPage = 0;

pageControl.pageIndicatorTintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];

pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];

[backView addSubview:pageControl];

 

/**

頂部滾動圖片

*/

UIScrollView *topView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, screenW, topPicH)];

topView.contentSize = CGSizeMake(screenW * pageCount, topPicH);

topView.bounces = NO;

topView.pagingEnabled = YES;

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

UIImageView *topPic = [[UIImageView alloc] init];

topPic.width = topPicW;

topPic.height = topPicH;

topPic.centerX = i * screenW + screenW / 2;

topPic.y = 0;

NSString *picName = [NSString stringWithFormat:@"page_top_%d",i];

topPic.image = [UIImage imageNamed:picName];

[topView addSubview:topPic];

}

[backView addSubview:topView];

self.topView = topView;

 

self.pageControl = pageControl;

[self.view addSubview:paiView];

[self.view addSubview:picView];

[self.view addSubview:ado_guideView];

self.guideView = ado_guideView;

self.picView = picView;

self.paiView = paiView;

 

}

#pragma mark - privateMethod

-(void)addGuideController{

 

if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isFirstEnterApp"]) {

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

ADo_ViewController * guide = [storyboard instantiateViewControllerWithIdentifier:@"ado"];

 

[self addChildViewController:guide];

guide.view.frame = self.view.bounds;

[self.view addSubview:guide.view];

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirstEnterApp"];

}

}

/**

* 模態到下個頁面

*

*/

- (void)go2MainVC:(UIButton *)btn

{

//UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@"你點中我了" message:nil delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];

//[alert show];

 

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

homeViewController *view=[self.storyboard instantiateViewControllerWithIdentifier:@"zhujiemian"];

[self.navigationController pushViewController:view animated:YES];

}

 

/**

* scrollView代理方法

*/

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

float offSetX = scrollView.contentOffset.x;

self.picView.layer.transform = CATransform3DMakeRotation(-offSetX*(M_PI)/screenW / 3, 0, 0, 1);

self.paiView.layer.transform = CATransform3DMakeRotation(-offSetX*(M_PI)/screenW / 3, 0, 0, 1);

self.pageControl.currentPage = scrollView.contentOffset.x / screenW;

 

 

if (self.pageControl.currentPage == 4) {

UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(screenW / 2 + offSetX - btnW / 2, screenH - 155, btnW, btnH)];

[nextBtn addTarget:self action:@selector(go2MainVC:) forControlEvents:UIControlEventTouchUpInside];

nextBtn.backgroundColor = [UIColor clearColor];

[scrollView addSubview:nextBtn];

}

 

 

self.topView.contentOffset = CGPointMake(offSetX, 0);

}

 

@end

 

 

//

// ADo_ViewController.m

// ADo_GuideView

//

// Created by dwx on 15/5/1.

// Copyright (c) 2015年 Nododo. All rights reserved.

//

 

#import "ADo_ViewController.h"

//#import "ADo_SecViewController.h"

#import "UIView+Extension.h"

#import "homeViewController.h"

#define screenW self.view.frame.size.width

#define screenH self.view.frame.size.height

#define pageCount 5

#define picH 2330 / 2

#define padding 200

#define topPicH 70

#define topPicW 112

#define btnH 100

#define btnW 140

@interface ADo_ViewController ()

/**

* 底部滾動圖片

*/

@property (nonatomic,strong)UIScrollView *guideView;

/**

* 球形圖片

*/

@property (nonatomic,strong)UIImageView *picView;

/**

* 牌型滾動

*/

@property (nonatomic,strong)UIImageView *paiView;

/**

* 指示

*/

@property (nonatomic,strong)UIPageControl *pageControl;

/**

* 頂部圖片滾動

*/

@property (nonatomic,strong)UIScrollView *topView;

@end

 

@implementation ADo_ViewController

 

- (void)viewDidLoad {

[super viewDidLoad];

/**

背景圖片

*/

UIImageView *backView = [[UIImageView alloc]initWithFrame:self.view.frame];

backView.image = [UIImage imageNamed:@"page_bg_35"];

[self.view addSubview:backView];

 

/**

滾動 輔助作用

*/

UIScrollView *ado_guideView = [[UIScrollView alloc] initWithFrame:self.view.frame];

ado_guideView.contentSize = CGSizeMake(screenW * pageCount, screenH);

ado_guideView.bounces = NO;

ado_guideView.pagingEnabled = YES;

ado_guideView.delegate = self;

ado_guideView.showsHorizontalScrollIndicator = NO;

 

/**

滾動球

 

*/

UIImageView *picView = [[UIImageView alloc] init];

picView.width = picH ;

picView.height = picH;

picView.centerX = screenW / 2;

picView.centerY = screenH + padding;

#warning 設定錨點是個坑

picView.layer.anchorPoint = CGPointMake(0.5, 0.5);

picView.image = [UIImage imageNamed:@"guider_qiu_35"];

 

/**

滾動牌

*/

UIImageView *paiView = [[UIImageView alloc] init];

paiView.width = picH;

paiView.height = picH;

paiView.centerX = screenW / 2 ;

paiView.centerY = screenH + padding;

paiView.layer.anchorPoint = CGPointMake(0.5, 0.5);

paiView.image = [UIImage imageNamed:@"guider_pai_35"];

 

/**

指標

*/

UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(screenW / 2 - 50, screenH - 20, 100, 20)];

pageControl.numberOfPages = 5;

pageControl.currentPage = 0;

pageControl.pageIndicatorTintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];

pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];

[backView addSubview:pageControl];

 

/**

頂部滾動圖片

*/

UIScrollView *topView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, screenW, topPicH)];

topView.contentSize = CGSizeMake(screenW * pageCount, topPicH);

topView.bounces = NO;

topView.pagingEnabled = YES;

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

UIImageView *topPic = [[UIImageView alloc] init];

topPic.width = topPicW;

topPic.height = topPicH;

topPic.centerX = i * screenW + screenW / 2;

topPic.y = 0;

NSString *picName = [NSString stringWithFormat:@"page_top_%d",i];

topPic.image = [UIImage imageNamed:picName];

[topView addSubview:topPic];

}

[backView addSubview:topView];

self.topView = topView;

 

self.pageControl = pageControl;

[self.view addSubview:paiView];

[self.view addSubview:picView];

[self.view addSubview:ado_guideView];

self.guideView = ado_guideView;

self.picView = picView;

self.paiView = paiView;

 

}

#pragma mark - privateMethod

-(void)addGuideController{

 

if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isFirstEnterApp"]) {

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

ADo_ViewController * guide = [storyboard instantiateViewControllerWithIdentifier:@"ado"];

 

[self addChildViewController:guide];

guide.view.frame = self.view.bounds;

[self.view addSubview:guide.view];

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirstEnterApp"];

}

}

/**

* 模態到下個頁面

*

*/

- (void)go2MainVC:(UIButton *)btn

{

//UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@"你點中我了" message:nil delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];

//[alert show];

 

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

homeViewController *view=[self.storyboard instantiateViewControllerWithIdentifier:@"zhujiemian"];

[self.navigationController pushViewController:view animated:YES];

}

 

/**

* scrollView代理方法

*/

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

float offSetX = scrollView.contentOffset.x;

self.picView.layer.transform = CATransform3DMakeRotation(-offSetX*(M_PI)/screenW / 3, 0, 0, 1);

self.paiView.layer.transform = CATransform3DMakeRotation(-offSetX*(M_PI)/screenW / 3, 0, 0, 1);

self.pageControl.currentPage = scrollView.contentOffset.x / screenW;

 

 

if (self.pageControl.currentPage == 4) {

UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(screenW / 2 + offSetX - btnW / 2, screenH - 155, btnW, btnH)];

[nextBtn addTarget:self action:@selector(go2MainVC:) forControlEvents:UIControlEventTouchUpInside];

nextBtn.backgroundColor = [UIColor clearColor];

[scrollView addSubview:nextBtn];

}

 

 

self.topView.contentOffset = CGPointMake(offSetX, 0);

}

 

@end

 

#import

 

@interface UIView (Extension)

@property (nonatomic, assign) CGFloat x;

@property (nonatomic, assign) CGFloat y;

@property (nonatomic, assign) CGFloat maxX;

@property (nonatomic, assign) CGFloat maxY;

@property (nonatomic, assign) CGFloat centerX;

@property (nonatomic, assign) CGFloat centerY;

@property (nonatomic, assign) CGFloat width;

@property (nonatomic, assign) CGFloat height;

@property (nonatomic, assign) CGSize size;

@end


 

#import "UIView+Extension.h"

 

@implementation UIView (Extension)

 

- (void)setX:(CGFloat)x

{

CGRect frame = self.frame;

frame.origin.x = x;

self.frame = frame;

}

 

- (CGFloat)x

{

return self.frame.origin.x;

}

 

- (void)setMaxX:(CGFloat)maxX

{

self.x = maxX - self.width;

}

 

- (CGFloat)maxX

{

return CGRectGetMaxX(self.frame);

}

 

- (void)setMaxY:(CGFloat)maxY

{

self.y = maxY - self.height;

}

 

- (CGFloat)maxY

{

return CGRectGetMaxY(self.frame);

}

 

- (void)setY:(CGFloat)y

{

CGRect frame = self.frame;

frame.origin.y = y;

self.frame = frame;

}

 

- (CGFloat)y

{

return self.frame.origin.y;

}

 

- (void)setCenterX:(CGFloat)centerX

{

CGPoint center = self.center;

center.x = centerX;

self.center = center;

}

 

- (CGFloat)centerX

{

return self.center.x;

}

 

- (void)setCenterY:(CGFloat)centerY

{

CGPoint center = self.center;

center.y = centerY;

self.center = center;

}

 

- (CGFloat)centerY

{

return self.center.y;

}

 

- (void)setWidth:(CGFloat)width

{

CGRect frame = self.frame;

frame.size.width = width;

self.frame = frame;

}

 

- (CGFloat)width

{

return self.frame.size.width;

}

 

- (void)setHeight:(CGFloat)height

{

CGRect frame = self.frame;

frame.size.height = height;

self.frame = frame;

}

 

- (CGFloat)height

{

return self.frame.size.height;

}

 

- (void)setSize:(CGSize)size

{

CGRect frame = self.frame;

frame.size = size;

self.frame = frame;

}

 

- (CGSize)size

{

return self.frame.size;

}

 

@end




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.