zoukankan      html  css  js  c++  java
  • 设置引导页(第一次登陆进入引导页)

    #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
  • 相关阅读:
    java8新特性之Lambda表达式入门
    小结
    Kafka入门
    关于java多线程初试
    关于Netty入门
    IOS UITableView代码添加数据源和指定委托
    C#读书笔记1
    vs2008 C# Windows Mobile 智能设备开发 初步1
    Microsoft ActiveSync简介(来自网络)
    winForm单击用户区可移动窗体,代码控制窗体最大适中
  • 原文地址:https://www.cnblogs.com/lantu1989/p/4941043.html
Copyright © 2011-2022 走看看