美文网首页
Xcode 11 beta + iOS 13 - 变化

Xcode 11 beta + iOS 13 - 变化

作者: ShenYj | 来源:发表于2019-06-21 20:33 被阅读0次

脱离iOS及原生开发许久, 去年做了几个月C#后换了家公司开始学习和写RN, 如今Xcode和iOS新系统纷纷来袭, 最近刚刚装了个beta版本Xcode

新建了工程, 刚开始看目录还以为自己选错了什么, 最后确认不是操作问题, 而是Xcode 11的新增变化, 对比了下AppDelegate, 初步来看是将原AppDelegate中的生命周期方法提取出去了, 加点log再看看

2019-06-21 20:18:26.054548+0800 InstallSource[23928:2286459] -[AppDelegate application:didFinishLaunchingWithOptions:]
2019-06-21 20:18:26.081472+0800 InstallSource[23928:2286459] -[SceneDelegate scene:willConnectToSession:options:]
2019-06-21 20:18:26.081895+0800 InstallSource[23928:2286459] -[SceneDelegate sceneWillEnterForeground:]
2019-06-21 20:18:26.082075+0800 InstallSource[23928:2286459] -[SceneDelegate sceneDidBecomeActive:]
2019-06-21 20:18:26.092754+0800 InstallSource[23928:2286459] -[AppDelegate application:didDiscardSceneSessions:]
2019-06-21 20:18:26.096867+0800 InstallSource[23928:2286459] -[AppDelegate application:configurationForConnectingSceneSession:options:]
2019-06-21 20:19:04.214283+0800 InstallSource[23928:2286459] -[SceneDelegate sceneWillResignActive:]
2019-06-21 20:19:10.384895+0800 InstallSource[23928:2286459] -[SceneDelegate sceneDidEnterBackground:]
2019-06-21 20:19:13.947999+0800 InstallSource[23928:2286459] -[SceneDelegate sceneWillEnterForeground:]
2019-06-21 20:19:14.240884+0800 InstallSource[23928:2286459] -[SceneDelegate sceneDidBecomeActive:]

然而这个DiscardScene...Discard的又是什么鬼...,又在log中加上了scene, 打印没发现什么明显区别, 看样子还得找资料详细看看

window新增属性windowScene

  • 获取状态栏高度
CGFloat statusBarHeight = 0;
if (@available(iOS 13.0, *)) {
    statusBarHeight = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame.size.height;
} else {
    // Fallback on earlier versions
    statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
}
  • 获取状态栏朝向
if (@available(iOS 13.0, *)) {
    _isPortrait = ![UIApplication sharedApplication].keyWindow.windowScene.interfaceOrientation;
} else {
    // Fallback on earlier versions
    _isPortrait = !UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
}
  • UIStatusBarManager.h文件
#if (defined(USE_UIKIT_PUBLIC_HEADERS) && USE_UIKIT_PUBLIC_HEADERS) || !__has_include(<UIKitCore/UIStatusBarManager.h>)
//
//  UIStatusBarManager.h
//  UIKit
//
//  Copyright © 2018 Apple Inc. All rights reserved.
//

#import <UIKit/UIWindowScene.h>

NS_ASSUME_NONNULL_BEGIN

UIKIT_EXTERN API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos)
@interface UIStatusBarManager : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

@property (nonatomic, readonly) UIStatusBarStyle statusBarStyle;
@property (nonatomic, readonly, getter=isStatusBarHidden) BOOL statusBarHidden;
@property (nonatomic, readonly) CGRect statusBarFrame; // returns CGRectZero if the status bar is hidden

@end


@interface UIWindowScene (StatusBarManager)

@property (nonatomic, readonly, nullable) UIStatusBarManager *statusBarManager API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);

@end

NS_ASSUME_NONNULL_END

#else
#import <UIKitCore/UIStatusBarManager.h>
#endif

相关文章

网友评论

      本文标题:Xcode 11 beta + iOS 13 - 变化

      本文链接:https://www.haomeiwen.com/subject/vwouqctx.html