假引導(dǎo) UIScrollView應(yīng)用

#import <UIKit/UIKit.h>

#import "UserGuideViewController.h"

#import "WeiBoViewController.h"

@interface AppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;

@end

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//判斷是不是第一次啟動(dòng)應(yīng)用

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

{

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

NSLog(@"第一次啟動(dòng)");

//如果是第一次啟動(dòng)的話,使用User (用戶引導(dǎo)頁(yè)面) 作為根視圖

UserGuideViewController *user = [[UserGuideViewController alloc] init];

self.window.rootViewController = user;

}

else

{

NSLog(@"不是第一次啟動(dòng)");

//如果不是第一次啟動(dòng)的話,使用weibo作為根視圖

WeiBoViewController *weibo = [[WeiBoViewController alloc] init];

self.window.rootViewController = weibo;

}

self.window.backgroundColor = [UIColor whiteColor];

//使鍵可見(jiàn)

[self.window makeKeyAndVisible];

return YES;

}

#import <UIKit/UIKit.h>

@interface WeiBoViewController : UIViewController

@property(strong,nonatomic) UIImageView *img;

@end

#import "WeiBoViewController.h"

@interface WeiBoViewController ()

@end

@implementation WeiBoViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

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

self.img.image = [UIImage imageNamed:@"5"];

[self.view addSubview:self.img];

}

#import <UIKit/UIKit.h>

#import "WeiBoViewController.h"

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

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

@interface UserGuideViewController : UIViewController

@property(strong,nonatomic) UIImageView *imageview1;

@property(strong,nonatomic) UIImageView *imageview2;

@property(strong,nonatomic) UIImageView *imageview3;

@property(strong,nonatomic) UIImageView *imageview4;

@property(strong,nonatomic) UIButton *button;

@property(strong,nonatomic) UIScrollView *scroll;

@end


#import "UserGuideViewController.h"

@interface UserGuideViewController ()

@end

@implementation UserGuideViewController

- (void)viewDidLoad {

[super viewDidLoad];

//調(diào)用用戶指導(dǎo)界面

[self initGuid];

// Do any additional setup after loading the view.

}

//引導(dǎo)界面的方法

-(void)initGuid

{

//初始化 UIScrollView 用戶滾動(dòng)視圖

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

//設(shè)置滾動(dòng)視圖的內(nèi)容大小

[self.scroll setContentSize:CGSizeMake(WIDTH*4, 0)];

//視圖整頁(yè)顯示

[self.scroll setPagingEnabled:YES];

//添加圖片到滾動(dòng)視圖上

self.imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];

[self.imageview1 setImage:[UIImage imageNamed:@"1.png"]];

[self.scroll addSubview:self.imageview1];

self.imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT)];

[self.imageview2 setImage:[UIImage imageNamed:@"2.png"]];

[self.scroll addSubview:self.imageview2];

self.imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH*2, 0, WIDTH, HEIGHT)];

[self.imageview3 setImage:[UIImage imageNamed:@"3.png"]];

[self.scroll addSubview:self.imageview3];

self.imageview4 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH*3, 0, WIDTH, HEIGHT)];

[self.imageview4 setImage:[UIImage imageNamed:@"4.png"]];

self.imageview4.userInteractionEnabled = YES;

[self.scroll addSubview:self.imageview4];

//打開(kāi)imageview4的用戶交互;否則下面的button無(wú)法響應(yīng)

self.button = [UIButton buttonWithType:UIButtonTypeCustom];

//在imageview4上加載一個(gè)button

//添加按鈕標(biāo)題

[self.button setTitle:@"按鈕" forState:UIControlStateNormal];

//設(shè)置按鈕的大小及位置

[self.button setFrame:CGRectMake(350, 700, 50, 30)];

//設(shè)置按鈕的顏色

self.button.backgroundColor = [UIColor brownColor];

//按鈕的監(jiān)聽(tīng)事件

[self.button addTarget:self action:@selector(firstpressed) forControlEvents:UIControlEventTouchUpInside];

//將按鈕添加到第四張圖片上

[self.imageview4 addSubview:self.button];

[self.view addSubview:self.scroll];

}

//button的方法

- (void)firstpressed

{

//點(diǎn)擊按鈕回到WeiBoViewController中調(diào)用

[self presentViewController:[[WeiBoViewController alloc]init] animated:YES completion:^{

// NSLog(@"button");

}];

}

效果圖片:


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容