简体   繁体   English

viewWillTransitionToSize和方向

[英]viewWillTransitionToSize and orientation

If I add property to UIViewController "myisLandscape" (BOOL) and I update this property everytime viewWillTransitionToSize is called 如果我向UIViewController“ myisLandscape”(BOOL)添加属性,并且每次调用viewWillTransitionToSize都更新此属性,

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{     
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    // will execute before rotation
    [coordinator animateAlongsideTransition:^(id  _Nonnull context) {

        self.myIsLandscape = (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]));

    } completion:^(id  _Nonnull context) {

        // will execute after rotation

    }];

}

beside this method, is there other method I need to update self.myIsLandscape so it will always be with correct value ? 除了这种方法,还有其他方法需要更新self.myIsLandscape,使其始终具有正确的值吗?

I need this property to access to check current orientation of UIViewController from background thread ( I don't want to use dispatch) 我需要此属性来访问以从后台线程检查UIViewController的当前方向(我不想使用分派)

- (void)viewWillTransitionToSize:(CGSize)size 
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

This method is a part of UIContentContainer Protocol. 此方法是UIContentContainer协议的一部分。 This protocol defines methods to redesign the contents of your view controller according to the size changes. 该协议定义了根据大小变化重新设计视图控制器内容的方法。 When you implement the below above method, it notifies the View Controller that it's view size is about to change. 当您实现以下方法时,它会通知视图控制器其视图大小即将更改。

So the check that you are doing, will return the correct value always. 因此,您正在执行的检查将始终返回正确的值。 No need to worry. 不用担心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM