自定义启动页

来源:互联网 发布:工业园网络建设方案 编辑:程序博客网 时间:2024/05/05 20:33
1.启动页自定义

(1)AppDelegate
    /**定义defaults对象往plist文件添加数据*/    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];       /**定义bool变量 用key取值  默认为NO*/    BOOL mark = [[defaults objectForKey:@"mark"] boolValue];       /**为NO是程序第一次运行*/    if (mark == NO) {               /**写数据*/        [defaults setBool:YES forKey:@"mark"];               /**同步*/        [defaults synchronize];        /**改变windows主窗口为scrollView实现的滑动视图*/        self.window.rootViewController = [[GuideViewController alloc] init];           }else{               /**如果为yes 说明不是第一次进入程序 那就进入欢迎界面*/        self.window.rootViewController = [[LaunchViewController alloc] init];           }

(2)欢迎页 每次打开程序都会显示


实现思路:1.新建一个类带xib 继承于UIViewController2.将28张图片用xib设置好并设置自动布局,所有view透明度设置为03.定义一个数组接受xib里的view  self.view.subviews就是数组(前提是要对图片view排好序)4.定义一个方法对数组里的每个元素进行透明度恢复   1.>定义一个成员变量index记录作为数组下标取值   2.>先定义退出条件 如果定义的index等于数组的count就改变当前windows的主控制器并 retrun;   3.>利用index从数组取元素,并执行动画改变其属性 alpha = 1;  4.>执行完动画后让index++; 然后利用延迟调用递归调用这个方法(动画几秒 就延迟几秒)实现代码:@interface LaunchViewController (){    int _index;    NSArray *_images;}    _images = [self.view subviews];       [self _initCtrl];   }- (void)_initCtrl{          if (_index == _images.count) {               self.view.window.rootViewController = [[RootTabBarController alloc] init];               return;           }         UIImageView *image = _images[_index];         [UIView animateWithDuration:.05 animations:^{                   image.alpha = 1;               }];       _index ++;       [self performSelector:@selector(_initCtrl) withObject:self afterDelay:.05];}



实现思路:1.新建一个类继承于UIViewController2.新建一个scrollView滑动视图3.新建个数组存放这些图片的名字4.用for循环将这些图片添加到滑动视图上5.遵守 UIScrollViewDelegate协议实现实时监测视图滑动的代理方法  在方法中判断如果滑动到了最后一张就跳转进程序实现代码:/**初始化启动页视图*/- (void)_initView{    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];    [self.view addSubview:scrollView];    scrollView.contentSize = CGSizeMake(ScreenW * 5, ScreenH);    scrollView.pagingEnabled = YES;    scrollView.delegate = self;       NSArray *guideImages = @[@"guide1@2x",                        @"guide2@2x",                        @"guide3@2x",                        @"guide4@2x",                        @"guide5@2x",];       NSArray *progressImages = @[@"guideProgress1@2x",                                @"guideProgress2@2x",                                @"guideProgress3@2x",                                @"guideProgress4@2x",                                @"guideProgress5@2x"];       for (int i = 0; i < guideImages.count; i++) {               UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:guideImages[i]]];        image.frame = CGRectMake(i*ScreenW, 0, ScreenW, ScreenH);        [scrollView addSubview:image];               UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:progressImages[i]]];        img.frame = CGRectMake((ScreenW - 86)/2.0, ScreenH - 13 - 30, 86, 13);        [image addSubview:img];    }   }/**实时监测滑动视图滚动*/-(void)scrollViewDidScroll:(UIScrollView *)scrollView{    RootTabBarController *root = [[RootTabBarController alloc] init];       /**  scrollView的x偏移量 + 屏幕宽 = scrollView.contentSize  */    /**  scrollView.contentSize.width -  scrollView.contentSize.width 就是目前多出来的的偏移量*/    CGFloat offset =(scrollView.contentOffset.x + ScreenW) - scrollView.contentSize.width;       /**判断滑动多少 该进入程序了*/    if (offset > 30) {               self.view.window.rootViewController = root;           }   }


0 0
原创粉丝点击