• 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

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

  • 相关阅读:
    各种工具网站汇总
    Python中numpy库unique函数解析
    matlab中集合运算函数——解析
    hash算法搜索获得api函数地址的实现,"kernel32.dll", "CreateThread"
    PEB及LDR链
    PE文件结构及其加载机制
    spring boot2.0一看就会的超详细快速入门(七)-访问静态资源
    spring boot2.0一看就会的超详细快速入门(六)-集成Thymeleaf模板引擎
    spring boot2.0一看就会的超详细快速入门(五)-开发人员工具devtools
    spring boot2.0一看就会的超详细快速入门(四)-自动配置原理
  • 原文地址:https://www.cnblogs.com/yang-shuai/p/5909673.html
Copyright © 2020-2023  润新知