加载在window上的引导页图片

首先加入QuartzCore.framework框架


AppDelegate.m


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    //判断是否为第一次进入程序
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];

        //04.25 遮罩层
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"industryR"];
        [[NSUserDefaults standardUserDefaults]synchronize];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

ViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
	if ([[NSUserDefaults standardUserDefaults] boolForKey:@"industryR"]) {
        //创建一个window,设置优先级
        window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
        window.hidden = NO;
        window.windowLevel = UIWindowLevelStatusBar + 1;
        
        imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"浮层发布功能"]];
        imageView.alpha = 0.8f;
        imageView.userInteractionEnabled = YES;
        imageView.frame = window.frame;
        [window addSubview:imageView];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = imageView.frame;
        [btn setTitle:nil forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
        [imageView addSubview:btn];
    }

}

-(void)clickBtn{//04.25 遮罩层
   
    //给windows一个动画,让window隐藏消失
    [[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"industryR"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    CATransition *animation = [CATransition animation];
    animation.duration = 2.0f;
    animation.type = kCATransitionFromBottom;
    [window.layer addAnimation:animation forKey:nil];
    [imageView removeFromSuperview];
    imageView.alpha = 1;
    window.hidden = YES;
    
}

这样就OK啦~放在window上面的引导页~

加载在window上的引导页图片_第1张图片


你可能感兴趣的:(ios,windows,动画,引导页)