您的位置:首页 > 移动开发 > IOS开发

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

2016-05-17 12:07 477 查看
iOS 应用添加开屏广告
在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];
}


文/Lonely__(简书作者)

原文链接:http://www.jianshu.com/p/6dc2713bf8d1

著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: