Xcode11之后Main.StoryBoard和SceneDelegate的移除与使用

一、Main.StoryBoard的使用

1、使用Main.StoryBoard(Default)

无需特殊处理,Xcode 11及其以上版本,默认生成用’Main.StoryBoard’模板

2、不使用Main.StoryBoard

  • a、在info.plist文件中找到Storyboard Name键值对,将其移除
    在这里插入图片描述
  • b、在TARGETS->info下找到Main storyboard file base name键值对,将其移除
    在这里插入图片描述
  • c、删除Main.storyboard
  • d、在侧边栏TARGETS->General下,找到Deployment Info项,在Status Bar Style选项中,勾选Supports multiple windows选项

二、SceneDelegate的使用

1、项目中使用SceneDelegate

  • a、打开SceneDelegate.m文件,在scenewillConnectToSession代理方法中,创建window窗口,初始化rootViewController
    -(void)scene:(UIScene*)scenewillConnectToSession:(UISceneSession*)sessionoptions:(UISceneConnectionOptions*)connectionOptions {
    UIWindowScenewindowScene = (UIWindowScene)scene;
    self.window= [[UIWindowalloc]initWithWindowScene:windowScene];
    self.window.frame = windowScene.coordinateSpace.bounds;
    self.window.rootViewController = ViewController.new;
    [self.window makeKeyAndVisible];
    }

2、 项目中不使用SceneDelegate

  • a、在info.plist文件中找到Application Scene Manifest键值对,将其移除
    在这里插入图片描述
  • b、在AppDelegate.m文件,移除UISceneSession lifecycle代理方法, 即application configurationForConnectingSceneSession 和applicationdidDiscardSceneSessions两个方法
    #pragma mark - UISceneSession lifecycle
    -(UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions )options {
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return[[UISceneConfigurationalloc]initWithName:@"Default Configuration"sessionRole:connectingSceneSession.role];
    }
    -(void)application:(UIApplication
    )applicationdidDiscardSceneSessions:(NSSet *)sceneSessions {
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
  • c、AppDelegate.h文件,新增window属性
    @property (strong, nonatomic) UIWindow *window;
  • d、AppDelegate.m文件中,在applicationdidFinishLaunchingWithOptions代理方法中,创建window窗口,初始化rootViewController
    -(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = UIColor.whiteColor;
    self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc]init]];
    [self.window makeKeyAndVisible];
    return YES;
    }
  • 17
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Xcode中制作LaunchScreen.storyboard可以通过以下步骤进行: 1. 打开Xcode并创建一个新的项目或打开现有的项目。 2. 在项目导航栏中,找到并选中名为LaunchScreen.storyboard的文件。 3. 在Interface Builder中,你将看到一个可视化的画布,用于创建你的Launch Screen界面。 4. 你可以在右侧的对象库中选择和拖拽各种视图元素到画布上,比如标签、图像视图、按钮等等。根据你的需求,自定义你的Launch Screen界面。 5. 使用自动布局和约束来确保你的Launch Screen在各种设备和屏幕尺寸下都能正确显示。你可以使用Auto Layout来指定视图之间的关系和位置,以及对内容进行自适应布局。 6. 添加所需的背景图像或启动图像。你可以在图像资源选项卡中,将你的图像文件拖拽到LaunchScreen.storyboard上,并将其设置为背景图像或者其他所需的位置。 7. 根据需要,你可以使用动画效果或过渡效果来提高Launch Screen的可视化效果。这可以通过在Launch Screen上添加动画视图或切换视图的方式来实现。 8. 在你完成Launch Screen的设计和布局后,你可以选择在应用程序设置中将其设置为你的项目的主要启动界面。进入“General”选项卡,找到“App Icons and Launch Images”部分,选择“Launch Screen File”并选择你的Launch Screen.storyboard文件。 通过以上步骤,你可以使用Xcode中的Interface Builder创建和设计Launch Screen.storyboard,以实现你想要的启动界面效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值