#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");
}];
}
效果圖片:





