美文网首页iOSiOS 引导页
iOS编程,怎么加引导页

iOS编程,怎么加引导页

作者: 霍伟健 | 来源:发表于2016-02-27 20:37 被阅读1134次

在AppDelegate中实现。

在AppDelegate中所有控件创建完成之后, 写引导页代码。注意:引导页在第一次进入软件的时候才会出现,因此每次进入运行的时候应该先从沙盒中读取,判断沙盒中是否含有文件, 没有文件的时候创建一个文件,以便下次运行的时候就不再出现引导页。具体代码如下。

/**  核心代码 */
#pragma mark ** 判断是否第一次进入
- (void)createGuidancePage {
    
    NSLog(@"%@", NSHomeDirectory());
    // 第一次进入, 从沙盒中读文件.
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"引导页"]) {
        // 沙盒中没有, 写一个文件.
        [[NSUserDefaults standardUserDefaults] setBool:1 forKey:@"引导页"];
        
        NSArray *arrayOfImageView = [NSArray array];
        
        //添加引导页图片
        arrayOfImageView = @[@"yindaoye1", @"yindaoye2", @"yindaoye3"];
        
        self.scrollViewForGuidancePage = [[UIScrollView alloc] init];
        
        //注意:添加在window上
        [self.window addSubview:self.scrollViewForGuidancePage];
        
        [_scrollViewForGuidancePage release];
        
        self.scrollViewForGuidancePage.bounces = NO;
        
        self.scrollViewForGuidancePage.pagingEnabled = YES;
        
        self.scrollViewForGuidancePage.showsHorizontalScrollIndicator = NO;
        
        self.scrollViewForGuidancePage.userInteractionEnabled = YES;
        
        self.scrollViewForGuidancePage.frame = self.window.frame;
        
        self.scrollViewForGuidancePage.contentSize = CGSizeMake(self.window.frame.size.width * arrayOfImageView.count, 0);
        
        self.scrollViewForGuidancePage.delegate = self;
        
        self.pageControlForGuidancePage = [[UIPageControl alloc] init];
        
        [self.window addSubview:self.pageControlForGuidancePage];
        
        [_pageControlForGuidancePage release];
        
        self.pageControlForGuidancePage.frame = CGRectMake(0, 0, self.window.frame.size.width / 2, 40);
        
        self.pageControlForGuidancePage.center = CGPointMake(self.scrollViewForGuidancePage.frame.size.width / 2, self.scrollViewForGuidancePage.frame.size.height - 40);
        
        self.pageControlForGuidancePage.numberOfPages = arrayOfImageView.count;
        
        //for循环, 在scrollView上添加照片
        for (int i = 0; i < arrayOfImageView.count; i++) {
            
            UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:arrayOfImageView[i]]];
            
            imageView.frame = CGRectMake(self.scrollViewForGuidancePage.frame.size.width * i, 0, self.scrollViewForGuidancePage.frame.size.width, self.scrollViewForGuidancePage.frame.size.height);
            
            [self.scrollViewForGuidancePage addSubview:imageView];
            
            imageView.userInteractionEnabled = YES;
            
            if (i == arrayOfImageView.count - 1) {
                
                //引导页最后一页"开始体验"按钮, 进入APP
                self.buttonForStart = [UIButton buttonWithType:UIButtonTypeCustom];
                
                [imageView addSubview:self.buttonForStart];
                
                [self.buttonForStart setTitle:@"开始体验" forState:UIControlStateNormal];
                
                self.buttonForStart.layer.borderWidth = 1;
                
                self.buttonForStart.layer.borderColor = [[UIColor whiteColor] CGColor];
                
                self.buttonForStart.layer.cornerRadius = 7;
                
                self.buttonForStart.layer.masksToBounds = YES;
                
                self.buttonForStart.frame = CGRectMake(0, 0, self.window.frame.size.width / 2, 40);
                
                self.buttonForStart.center = CGPointMake(self.window.frame.size.width / 2, self.window.frame.size.height - 100);
                
                [self.buttonForStart addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
                
            }
            
        }
        
    }
    
}

/** button 的点击事件,点击之后进入主页. */


- (void)start {
    
    //从父视图上移除
    [self.pageControlForGuidancePage removeFromSuperview];
    
    [self.scrollViewForGuidancePage removeFromSuperview];
    
}

/** scrollView 的Delegate, 让pageControl跟着scrollView的contentOffset的变化而变化. */


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    self.pageControlForGuidancePage.currentPage = self.scrollViewForGuidancePage.contentOffset.x / self.window.frame.size.width;
    
}

相关文章

  • iOS编程,怎么加引导页

    在AppDelegate中实现。 在AppDelegate中所有控件创建完成之后, 写引导页代码。注意:引导页在第...

  • ios引导页

    首先修改 App Transport Security SettingsAllow Arbitrary Loads...

  • iOS 引导页

    在AppDelegate.m中:我们需要两个Viewcongtroller来实现;myViewController...

  • ios 引导页

    目标功能 能够快速实现普通引导页功能. 提供自定义view的加载模式. 提供特定样式的加载模式,只需要配置即可. ...

  • iOS引导页

    在我们项目中经常会用到引导页,引导页主要功能就是向用户展示你的产品。 这是我写的一个例子的效果图(图片是随便找的):

  • iOS引导页

    引导页是App中的基本功能,指导用户理解某些操作或版本变化等等。 引导页可能出现在任何时候,页面内容会根据可交互度...

  • 关于iOS设置引导页优化问题

    现在,总结一下设置iOS app引导页,所误入的坑 之前呢,所提交的版本没有怎么关注过引导页的优化问题,自认为让设...

  • iOS引导页、启动页

    前言 这里使用 launchScreen 、.storyboard 文件创建启动图和引导页。首次打开项目或者更新后...

  • 引导页的实现

    首先新建一个类继承自UIViewController,加一个满屏的ScrollView,用于实现引导页。在引导页的...

  • iOS 引导页适配

    1,图片适配,最早以前是自己命名规范,例如@1x,@2x,@3x等,3套图基本上就够用了 2,在iPhone X之...

网友评论

本文标题:iOS编程,怎么加引导页

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