티스토리 뷰

반응형

[ 이슈 ]

 

A와 B는 다른 preferredStatusBarStyle 을 가지고 있습니다. 

 

class AViewController: UIViewController {

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
    
    
    ...
}


class BViewController: UIViewController {

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .darkContent
    }
    
    ...
 }

 

 

1. A에서 B를 present 할 때, B의 modalPresentationStyle을 fullScreen으로 하면 B에 오버라이딩한 statusBarStyle로 잘 나옵니다. 

2. A에서 B를 present 할 때, B의 modalPresentationStyle을 overFullScreen 으로 하면 A에 오버라이딩한 statusBarStyle로 나옵니다.

 

 

실제 디버깅 포인트를 걸고 돌려보면 1번의 경우 B를 present 할 때 B의 preferredStatusBarStyle 가 불리지만

2번의 경우,  B를 present 할 때  A의 preferredStatusBarStyle가 불립니다. 

 

 

[ modalPresentationCapturesStatusBarAppearance ]

 

그 이유는 바로 UIViewController의  modalPresentationCapturesStatusBarAppearance  프로퍼티 때문입니다.

 

present(_:animated:completion:) 메소드를 사용할 때, 

presented controller의 modalPresentationStyle이 오직 fullScreen일 때만 

status bar appearance control이 presenting 뷰컨트롤러에서  presented 뷰컨트롤러로 넘어가게 됩니다. 

(그래서 위의 예제에서 fullScreen 모드에서만 B의 preferredStatusBarStyle 가 불렸던 것입니다.)

 

 

modalPresentationCapturesStatusBarAppearance  프로퍼티는

non-fullscreen 으로 presented 된 뷰컨트롤러가 status bar appearance 에 대한 control을 가질 지 정하는 프로퍼티 이고 

디폴트값은 false 입니다.

 

이 프로퍼티를  true로 설정하면 non-fullscreen 으로 presented 되었어도 presented view controller가 status bar appearance 에 대한 컨트롤을 가지게 됩니다!! 

 

 

 

[ modalPresentationCapturesStatusBarAppearance 를 true로 설정해보자 ]

 

그럼 BViewController 의  modalPresentationCapturesStatusBarAppearance 를 true 로 바꿔봅시다.

 

class BViewController: UIViewController {

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .darkContent
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.modalPresentationCapturesStatusBarAppearance = true
     }
 }

 

이제 modalPresentationStyle에 상관없이 B에 오버라이딩한 statusBarStyle로 잘 나오는 것을 볼 수 있습니다. 

 

 

반응형
댓글