2017-10-01 4 views
0

statusBarFrame을 가져 오는 것이 iOS 11에서 올바른 값을 반환하지 않는 것으로 나타났습니다. 안전 영역을 사용하여 앞으로이 문제를 해결할 수있는 더 나은 방법이있을 수 있지만 실제로는 statusBarFrame은 iOS 11 이전처럼 작동합니다. 일반적으로 어떻게 사용합니까?iOS 11의 StatusBarFrame

UIApplication.shared.statusBarFrame 

iOS 11 이전에 내 앱이 제대로 작동하는지 확인했습니다.하지만 iOS 11에서는 역방향으로 표시됩니다. 예를 들어, iPhone의 경우 세로 20 인치, 가로 0 인치이지만 세로로 0, 가로로 20을 반환합니다.

상태 표시 줄 문제와 관련된 모든 게시물을 읽었으며이 문제를 해결하지 못했습니다.

타이밍 문제로 보입니다. DispatchQueue.main.async {} 클로저에서 statusBarFrame을 사용하는 코드를 래핑 했으므로 제대로 작동합니다. 나는 이것을 더 많은 bandaid라고 생각할 것이다. 적절한 해결책을 찾고 있습니다.

감사합니다.

감사합니다.

답변

0

응용 프로그램 실행 중 또는보기 컨트롤러의 viewDidLoad 중에 상태 표시 줄의 배경색을 설정할 수 있습니다. 여기 그것이 나를 위해, 다음과 같은 방식으로 작동합니다.

enter image description here

: 여기

extension UIApplication { 

    var statusBarView: UIView? { 
     return value(forKey: "statusBar") as? UIView 
    } 

} 

// Set upon application launch, if you've application based status bar 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     UIApplication.shared.statusBarView?.backgroundColor = UIColor.red 
     return true 
    } 
} 


or 
// Set it from your view controller if you've view controller based statusbar 
class ViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     UIApplication.shared.statusBarView?.backgroundColor = UIColor.red 
    } 

} 



이 결과