iOS: How to run a function after Device has Rotated (Swift)

后端 未结 3 1212
傲寒
傲寒 2020-12-02 16:52

I have one UIView which is not using Auto-Layout and some components are displayed based on their percent of X and Y co-ordinates from the main view.

Previously I wo

3条回答
  •  时光说笑
    2020-12-02 17:19

    Although not asked for here Objective C version:

    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {
    [coordinator animateAlongsideTransition:^(id  _Nonnull context) {
    
        // change any properties on your views
    
    } completion:^(id  _Nonnull context) {
        UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
        if( UIDeviceOrientationIsPortrait(orientation) ) {
            NSLog(@"portrait");
        } else {
            NSLog(@"landscape");
        }  
    }];
    }
    

提交回复
热议问题