之前很奇怪app啟動(dòng)之后的廣告展示是怎么處理的茄猫,特意試了下效果誊抛,下面是我簡(jiǎn)單實(shí)現(xiàn)的一個(gè)廣告展示效果代碼如下:在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];
}