zoukankan      html  css  js  c++  java
  • iOS 界面启动时,功能新特征显示

    APP新启动的时候,都会有几张新的图片滑动,才能到主的界面。现在,我们新建一个控制器,专门来处理新特性,直接上代码.

    第一步:新建一个NewfeatureController

    //
    //  HWNewfeatureController.m
    //  Weibo
    //
    //  Created by jys on 15/3/24.
    //  Copyright (c) 2015年 weibo. All rights reserved.
    //
    
    #import "HWNewfeatureController.h"
    #import "HWTabBarViewController.h"
    
    #define HWNewfeatureCount 4
    
    @interface HWNewfeatureController ()<UIScrollViewDelegate>
    
    @property (nonatomic,weak) UIPageControl *pageControl;
    @property (nonatomic,weak) UIScrollView *scrollView;
    
    @end
    
    @implementation HWNewfeatureController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        //1.创建一个scrollView,显示所有的新特性图片
        UIScrollView *scrollView=[[UIScrollView alloc] init];
        scrollView.frame=self.view.bounds;
        [self.view addSubview:scrollView];
        self.scrollView=scrollView;
        
        //2.添加图片到scrollView中
        CGFloat scrollW=scrollView.width;
        CGFloat scrollH=scrollView.height;
        
        for (int i=0; i<HWNewfeatureCount; i++) {
            UIImageView *imageView=[[UIImageView alloc] init];
            imageView.width=scrollW;
            imageView.height=scrollH;
            imageView.y=0;
            imageView.x=i*scrollW;
            
            //显示图片
            NSString *name = [NSString stringWithFormat:@"new_feature_%d", i + 1];
            imageView.image=[UIImage imageNamed:name];
            [scrollView addSubview:imageView];
            
            // 如果是最后一个imageView,就往里面添加其他内容
            if (i == HWNewfeatureCount - 1) {
                [self setupLastImageView:imageView];
            }
        }
        
        //3.设置scrollView的其它属性
        //如果想要某个方向上不能滚动,那么这个方向对应的尺寸数值传0即可
        scrollView.contentSize=CGSizeMake(scrollView.width*HWNewfeatureCount, 0);
        scrollView.bounces=NO;//去除弹簧效应
        scrollView.pagingEnabled=YES;//分页,一张一张的滚动
        scrollView.showsHorizontalScrollIndicator=NO;//没有滚动条
        scrollView.delegate = self;
        
        //4.添加pageController分页,展示目前看的是第几页
        UIPageControl *pageControl=[[UIPageControl alloc] init];
        pageControl.numberOfPages=HWNewfeatureCount;
        pageControl.backgroundColor=[UIColor redColor];
        pageControl.currentPageIndicatorTintColor=HWColor(253, 98, 42);
        pageControl.pageIndicatorTintColor=HWColor(189, 189, 189);
        pageControl.centerX=scrollW*0.5;
        pageControl.centerY=scrollH-50;
        [self.view addSubview:pageControl];
        self.pageControl=pageControl;
        
        // UIPageControl就算没有设置尺寸,里面的内容还是照常显示的,该控件相对特别
        //    pageControl.width = 100;
        //    pageControl.height = 50;
        //    pageControl.userInteractionEnabled = NO;
    }
    
    //当前页面滚到哪页
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        double page=scrollView.contentOffset.x/scrollView.width;
        self.pageControl.currentPage=(int)(page+0.5);
    }
    
    /**
     *  初始化最后一个imageView
     *
     *  @param imageView <#imageView description#>
     */
    -(void)setupLastImageView:(UIImageView *)imageView
    {
        //开启交互功能
        imageView.userInteractionEnabled=YES;
        
        //1.分享给大家
        UIButton *shareBtn=[[UIButton alloc]init];
        [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_false"]  forState:UIControlStateNormal];
        [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
        
        [shareBtn setTitle:@"分享给大家" forState:UIControlStateNormal];
        [shareBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        shareBtn.titleLabel.font=[UIFont systemFontOfSize:15];
        shareBtn.width=200;
        shareBtn.height=30;
        shareBtn.centerX=imageView.width*0.5;
        shareBtn.centerY=imageView.height*0.65;
        // top left bottom right
        shareBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        [shareBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
        [imageView addSubview:shareBtn];
        
        //2.开始微博
        UIButton *startBtn=[[UIButton alloc] init];
        [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        startBtn.size=startBtn.currentBackgroundImage.size;
        startBtn.centerX=imageView.width*0.5;
        startBtn.centerY=imageView.height*0.75;
        [startBtn setTitle:@"开始微博" forState:UIControlStateNormal];
        [startBtn addTarget:self action:@selector(startClick) forControlEvents:UIControlEventTouchUpInside];
        [imageView addSubview:startBtn];
        //startBtn.centerX=imageView
        
    }
    
    
    -(void)shareClick:(UIButton *)shareBtn
    {
        //状态取反
        shareBtn.selected=!shareBtn.isSelected;
    }
    
    //开始微博
    -(void)startClick
    {
        UIWindow *window=[UIApplication sharedApplication].keyWindow;
        window.rootViewController=[[HWTabBarViewController alloc]init];
        
    }
    
    
    @end

    上面的代码中,需要注意的是:

    开始微博,显示主界面时,请使用rootViewController来处理,如果用其它方式,新特性界面并没有销毁,留下隐患。

    - (void)startClick
    {
        // 切换到HWTabBarController
        /*
         切换控制器的手段
         1.push:依赖于UINavigationController,控制器的切换是可逆的,比如A切换到B,B又可以回到A
         2.modal:控制器的切换是可逆的,比如A切换到B,B又可以回到A
         3.切换window的rootViewController
         */
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        window.rootViewController = [[HWTabBarViewController alloc] init];
        
        // modal方式,不建议采取:新特性控制器不会销毁
    //    HWTabBarViewController *main = [[HWTabBarViewController alloc] init];
    //    [self presentViewController:main animated:YES completion:nil];
    }

    第二步,程序启动时,判断版本号。如果版本号不一致,则显示新特性。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // 1.创建窗口
        self.window = [[UIWindow alloc] init];
        self.window.frame = [UIScreen mainScreen].bounds;
        
        // 2.设置根控制器
        NSString *key = @"CFBundleVersion";
        // 上一次的使用版本(存储在沙盒中的版本号)
        NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:key];
        // 当前软件的版本号(从Info.plist中获得)
        NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
        
        if ([currentVersion isEqualToString:lastVersion]) { // 版本号相同:这次打开和上次打开的是同一个版本
            self.window.rootViewController = [[HWTabBarViewController alloc] init];
        } else { // 这次打开的版本和上一次不一样,显示新特性
            self.window.rootViewController = [[HWNewfeatureViewController alloc] init];
            
            // 将当前的版本号存进沙盒
            [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:key];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
        
        // 3.显示窗口
        [self.window makeKeyAndVisible];
        return YES;
    }
  • 相关阅读:
    【DFS】XIII Open Championship of Y.Kupala Grodno SU Grodno, Saturday, April 29, 2017 Problem D. Divisibility Game
    【二分】【三分】【计算几何】XIII Open Championship of Y.Kupala Grodno SU Grodno, Saturday, April 29, 2017 Problem L. Lines and Polygon
    【线段树】XIII Open Championship of Y.Kupala Grodno SU Grodno, Saturday, April 29, 2017 Problem J. Jedi Training
    【贪心】【后缀自动机】XIII Open Championship of Y.Kupala Grodno SU Grodno, Saturday, April 29, 2017 Problem E. Enter the Word
    【转载】随机生成k个范围为1-n的随机数,其中有多少个不同的随机数?
    【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem H. Path or Coloring
    【枚举】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem D. Cutting Potatoes
    【找规律】【递归】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem F. Doubling
    【贪心】Codeforces Round #436 (Div. 2) D. Make a Permutation!
    【计算几何】【圆反演】计蒜客17314 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 G. Finding the Radius for an Inserted Circle
  • 原文地址:https://www.cnblogs.com/jys509/p/4370445.html
Copyright © 2011-2022 走看看