美文网首页
假引导 UIScrollView应用

假引导 UIScrollView应用

作者: lichengjin | 来源:发表于2016-03-14 23:18 被阅读36次

    #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 {

    //判断是不是第一次启动应用

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

    {

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

    NSLog(@"第一次启动");

    //如果是第一次启动的话,使用User (用户引导页面) 作为根视图

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

    self.window.rootViewController = user;

    }

    else

    {

    NSLog(@"不是第一次启动");

    //如果不是第一次启动的话,使用weibo作为根视图

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

    self.window.rootViewController = weibo;

    }

    self.window.backgroundColor = [UIColor whiteColor];

    //使键可见

    [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];

    //调用用户指导界面

    [self initGuid];

    // Do any additional setup after loading the view.

    }

    //引导界面的方法

    -(void)initGuid

    {

    //初始化 UIScrollView 用户滚动视图

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

    //设置滚动视图的内容大小

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

    //视图整页显示

    [self.scroll setPagingEnabled:YES];

    //添加图片到滚动视图上

    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];

    //打开imageview4的用户交互;否则下面的button无法响应

    self.button = [UIButton buttonWithType:UIButtonTypeCustom];

    //在imageview4上加载一个button

    //添加按钮标题

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

    //设置按钮的大小及位置

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

    //设置按钮的颜色

    self.button.backgroundColor = [UIColor brownColor];

    //按钮的监听事件

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

    //将按钮添加到第四张图片上

    [self.imageview4 addSubview:self.button];

    [self.view addSubview:self.scroll];

    }

    //button的方法

    - (void)firstpressed

    {

    //点击按钮回到WeiBoViewController中调用

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

    // NSLog(@"button");

    }];

    }

    效果图片:

    相关文章

      网友评论

          本文标题:假引导 UIScrollView应用

          本文链接:https://www.haomeiwen.com/subject/dhnflttx.html