zoukankan      html  css  js  c++  java
  • iOS启动页加载广告

    1、定义全局成员变量

    @interface AppDelegate ()

    @property (strong, nonatomic) UIImageView *adImageView;

    @property (strong, nonatomic) UINavigationController *rootNavi;

    @end

    2、实现简单广告界面

    @implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

        TextViewController* mainVC = [[TextViewController alloc] init];

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mainVC];

        self.rootNavi = nav;

        if ([[UIDevice currentDevice].systemVersion doubleValue] < 7.0) {

            [nav.navigationBar setBarTintColor:[UIColor clearColor]];

        } else {

            [nav.navigationBar setTintColor:[UIColor clearColor]];

        }

        注意:一定要设置空的rootViewController

        UIViewController *emptyView = [[ UIViewController alloc ] initWithNibName:nil bundle:nil];

        self. window .rootViewController = emptyView;

        

        self.adImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];

        [self.adImageView setImage:[UIImage imageNamed:@"bg_welcome"]];

        [self.window addSubview:self.adImageView];

        [self performSelector:@selector(removeAdImageView) withObject:nil afterDelay:3];

        

        self.window.backgroundColor = [UIColor whiteColor];

        [self.window makeKeyAndVisible];

        

        return YES;

    }

    3、移除广告页重新设置根控制器

    - (void)removeAdImageView

    {

        [UIView animateWithDuration:0.3f animations:^{

            self.adImageView.transform = CGAffineTransformMakeScale(0.5f,0.5f);

            self.adImageView.alpha = 0.f;

        } completion:^(BOOL finished) {

            [self.adImageView removeFromSuperview];

    //        self.window.rootViewController = self.rootNavi;

            [self restoreRootViewController:self.rootNavi];

        }];

    }

    - (void)restoreRootViewController:(UIViewController *)rootViewController

    {

        typedef void (^Animation)(void);

        UIWindow* window = self.window;

        

        rootViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        Animation animation = ^{

            BOOL oldState = [UIView areAnimationsEnabled];

            [UIView setAnimationsEnabled:NO];

            window.rootViewController = rootViewController;

            [UIView setAnimationsEnabled:oldState];

        };

        

        [UIView transitionWithView:window

                          duration:0.5f

                           options:UIViewAnimationOptionTransitionCrossDissolve

                        animations:animation

                        completion:nil];

    }

    @end

    4、如需实现倒计时、跳过只需要自定义View去操作就ok

    ............

  • 相关阅读:
    20170228 Z_po_send_email
    MRP 流程
    MRP 中的数据元素
    笔记:使用 Protel 99 SE 改一块车充 PCB
    PCB 锣板和半孔工艺的差别
    笔记:LIR2032 电池充电记录
    笔记:开源协议 Apache 2 和 GPL 兼容
    FastAdmin 在 CRUD 时出现 exec() has been disabled for security reasons 怎么办?
    FastAdmin 学习线路 (2018-09-09 增加 Layer 组件)
    记录一下变压器的焊盘问题
  • 原文地址:https://www.cnblogs.com/yang-shuai/p/5909673.html
Copyright © 2011-2022 走看看