我的GitHub
0%

iOS重新开始

重新添加rootview

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// SceneDelegate.swift

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
let tmpScene = (scene as? UIWindowScene)
if ((tmpScene) != nil) {
window = UIWindow.init(windowScene: tmpScene!)
let viewCotroller = HomeViewController()
let navigationViewController = UINavigationController.init(rootViewController: viewCotroller)
navigationViewController.navigationBar.barTintColor = WXTools.ColorHex("#213241")
window?.rootViewController = navigationViewController
window?.makeKeyAndVisible()
} else { return }
}

布局从nav以下开始

1
self.navigationController?.navigationBar.isTranslucent = false

去掉nav下面的横线

1
2
3
//        去除下划线
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()

nav

1
2
3
4
// 状态栏高度
let statusBarHeight = UIApplication.shared.statusBarFrame.height
// nav高度
let navigationBarHeight = (navigationController?.navigationBar.frame.height)!

移除SceneDelegate

1.修改Info.plist

移除如下信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>

2.删除SceneDelegate.swift文件

3.修改AppDelegate.swift文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = UIColor.white
self.window?.rootViewController = ViewController()
self.window?.makeKeyAndVisible()
return true
}

}

snap

我是阿星,阿星的阿,阿星的星!