社交类项目总结

1.0 搭建初始架构

2015-12-25  本文已影响99人  iOS_Cqlee

First Chapter

1.整理基本架构

2.程序入口

以创建广告的设置来说,使用storyboard,viewcontroller,添加广告图片,添加跳转按钮,一旦点击图片直接跳转到广告的页面,点击跳转按钮直接跳过广告,同时在设置一个定时在指定时间内跳转到UITabBarcontroller,不然一直停留在广告页面会给用户不好的使用感受.

具体代码如下

- (void)viewDidLoad{
    //取出屏幕的大小
     CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
     //根据屏幕大小进行判断用户手机的型号,配置使storyboard的背景和启动图片一直,一般来说最好不要出现数字,可以将数字抽成宏,简单的介绍就不直接抽宏了
     if (screenH == 736) {
    // 6 plus\6s plus
     self.bgImageView.image = [UIImage imageNamed:@"LaunchImage-800-Portrait-736h@3x"];
    }else if(screenH == 667){
     // 6\6s
     self.bgImageView.image = [UIImage imageNamed:@"LaunchImage-800-667h@2x"];
    }else if (screenH == 568){
    // 5\5s
     self.bgImageView.image = [UIImage imageNamed:@"LaunchImage-568h@2x"];
    }else if (screenH == 480){
     self.bgImageView.image = [UIImage imageNamed:@"LaunchImage"];
     }

 //一般来说图片是不能进行点击的,要想对图片进行点击,必须为图片设置为可点击的
    self.adImageView.userInteractionEnabled = YES;

  //为广告图片添加手势
    [self.adImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adClick)]];

 //显示广告图片
 BOOL hadAd = NO;
    if (hadAd) {
    //加载沙盒图片
     }else{
     //从来没有加载过的服务器图片
     self.adImageView.image = [UIImage imageNamed:@"图片名"];
     hadAd = YES;
    }
    
    //添加计时器,之后要控制,把定时设置为属性,同时记录下剩下的时间
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
    //注意必须添加runloop否则定时器是无法进行的
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    
    //设置广告持续的时间
    self.leftTime = 3;
    
    
}

//定时器执行的方法
- (void)updateTime{
    //每次时间减一
    self.leftTime--;
    //给用户显示
    NSString *title = [NSString stringWithFormat:@"%zd",self.leftTime];
   //设置跳过按钮的文字随定时器变动
   [self.skipBtn setTitle:title forState:UIControlStateNormal];
   
    //时间到跳专页面
    if (self.leftTime == -1) {
        //切换到app的首页
        [self skip];
    }
}


/** 广告点击 */
- (void)adClick{
    //一旦点击了广告需移除定时器
    [self.timer invalidate];
    self.timer = nil;
    //跳转广告页面
    [UIApplication sharedApplication].keyWindow.rootViewController = 广告的页面(这在创建新viewcontroller中添加一个webview)
}


/** 点击跳过 */
- (IBAction)skip {
    //一旦点击跳过或者时间到了,移除定时器
    [self.timer invalidate];
    //定时器移除之后,清空
    self.timer = nil;
    //跳转到自定义主页面
    [UIApplication sharedApplication].keyWindow.rootViewController = [[CqTabBarController alloc] init];
    
}

上一篇下一篇

猜你喜欢

热点阅读