加载在window上的引导页图片

本文介绍如何在iOS应用中实现首次启动时的引导页面,包括利用QuartzCore.framework框架添加过渡动画效果,并通过NSUserDefaults来判断和控制是否显示引导页。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先加入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上面的引导页~



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值