记录删除storyboard用纯代码布局
记录删除storyboard用纯代码布局
[toc]
目录变化
首先来看一下 Xcode13 创建项目的目录,比之前的旧版本多了 SceneDelegate.h 和 SceneDelegate.m
两个文件

SceneDelegate
从 Xcode11开始,创建新的iOS项目的模版中会带有 SceneDelegate
类,并且在 plist 文件中会有一个 Application Scene Manifest
配置,AppDelegate.m
中新增了两个管理 SceneDelegate 的函数 ,分别是 application(_:configurationForConnecting:options:)
和 application(_:didDiscardSceneSessions:)
。
SceneDelegate.h 和 SceneDelegate.m
两个文件这两个文件一般用于 ipadOS 的分屏功能的。
删除 storyboard
将项目中的故事板删除到垃圾桶
然后将 General 下的 Main Interface 中的 Main 删除掉

接着删除 Info 下的 Application Scene Manifest

删除 SceneDelegate.h 和 SceneDelegate.m
两个文件
将 SceneDelegate.h
和 SceneDelegate.m
这两个文件扔到垃圾桶
然后删除 Appdelegate.m
中的一下代码
#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 [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)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.
}
Appdelegate.h
中要添加 window 属性
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow * window;
@end
然后在 Appdelegate.m
中的 didFinishLaunchingWithOptions
函数中添加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 创建UIWindow
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// 设置UIWindow的背景颜色
self.window.backgroundColor = [UIColor grayColor];
ViewController *homeVC = [[ViewController alloc] init];
UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeVC];
self.window.rootViewController = homeNav;
[self.window makeKeyAndVisible];
return YES;
}
接下来就可以用纯代码进行编写了!