美文网首页iOS猿媛圈带我飞iOS动画
ios app启动图片,之后的广告图片效果

ios app启动图片,之后的广告图片效果

作者: Lonely__M | 来源:发表于2015-08-12 11:11 被阅读4021次

    之前很奇怪app启动之后的广告展示是怎么处理的,特意试了下效果,下面是我简单实现的一个广告展示效果代码如下:在AppDelegate.h中的代码

    #import <UIKit/UIKit.h>
     
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
     
    @property (strong, nonatomic) UIWindow *window;
    @property (strong, nonatomic) UIImageView *adImageView;
    @property (strong, nonatomic) UINavigationController *rootNavi;
     
    @end 
    

    在AppDelegate.m中的代码

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
        // Override point for customization after application launch.
        AlertDemoViewController *vc = [[AlertDemoViewController alloc]init];
        
        UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:vc];
        
        if (isIOS7) {
            [navi.navigationBar setBarTintColor:[UIColor clearColor]];
        }else{
            [navi.navigationBar setTintColor:[UIColor clearColor]];
        }
        self.rootNavi = navi;
        
        //self.window.rootViewController = navi;
        
        self.adImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];
        [self.adImageView setImage:[UIImage imageNamed:@"tmplecture"]];
        [self.window addSubview:self.adImageView];
        [self performSelector:@selector(removeAdImageView) withObject:nilafterDelay:3];
        
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }
     
    - (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;
        }];
    }
    
    

    淡入淡出更换 rootViewController

    - (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];
    }
    

    相关文章

      网友评论

      • 马铃薯蜀黍:加一张跟启动图一样的图片就好了
      • f98522eca813:楼主有demo么,你这么截取代码,看不太明白~~~
      • Bob林::completion:
      • FengxinLi:请问楼主- (void)restoreRootViewController:(UIViewController *)rootViewController这个方法在哪用呢?
        Bob林:@Fengxinliju 注释他第一个动画,直接用第二个动画传入根控制器就行了

      本文标题:ios app启动图片,之后的广告图片效果

      本文链接:https://www.haomeiwen.com/subject/tfiiqttx.html