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
............