标签:
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
#import "AppDelegate.h" #import "GuideViewController.h" #import "RootViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; // 判断是否是第一次登陆 if (![[NSUserDefaults standardUserDefaults] objectForKey:@"FirstLaunch"]) { [[NSUserDefaults standardUserDefaults] setObject:@(true) forKey:@"FirstLaunch"]; self.window.rootViewController = [[GuideViewController alloc] init]; }else{ self.window.rootViewController = [[RootViewController alloc] init]; } [self.window makeKeyAndVisible]; return YES; } @end
#import <UIKit/UIKit.h> @interface GuideViewController : UIViewController @end
#import "GuideViewController.h" #import "RootViewController.h" @interface GuideViewController () @end @implementation GuideViewController - (void)viewDidLoad { [super viewDidLoad]; // 初始化scrollView UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // 隐藏水平滚动条 scrollView.showsHorizontalScrollIndicator = NO; // 翻页效果 scrollView.pagingEnabled = YES; // 设置scrollView的内容窗口大小 scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 3, [UIScreen mainScreen].bounds.size.height); [self.view addSubview:scrollView]; // 设置滚动图片 NSArray *array = [[NSArray alloc] initWithObjects:@"1-1.jpg",@"1-2.jpg",@"1-3.jpg", nil]; for (int i = 0; i < array.count; i++) { UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:array[i]]]; imageView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width * i, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); [scrollView addSubview:imageView]; imageView.tag = 1000 + i; } // 获取最后一个imageView,然后在其上面加button UIImageView *imgView = [self.view viewWithTag:1002]; // 父视图要可操作,否则其上面的子视图(button)不可操作 imgView.userInteractionEnabled = YES; // 设置button UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 150)/2.0, [UIScreen mainScreen].bounds.size.height - 120, 150, 80); [btn setBackgroundColor:[UIColor clearColor]]; [btn setTitle:@"马上体验" forState:0]; [btn setTitleColor:[UIColor redColor] forState:0]; [btn addTarget:self action:@selector(comeToRootController:) forControlEvents:UIControlEventTouchUpInside]; [imgView addSubview:btn]; } - (void)comeToRootController:(UIButton *)sender{ RootViewController *root = [[RootViewController alloc] init]; UIApplication *app = [UIApplication sharedApplication]; app.keyWindow.rootViewController = root; } @end
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end
#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor orangeColor]; } @end
标签:
原文地址:http://www.cnblogs.com/lantu1989/p/4941043.html