View rotation notifications: why didRotateFromInterfaceOrientation: doesn't get called?

前端 未结 2 2088
暖寄归人
暖寄归人 2020-12-31 09:25

I\'m trying to detect any device orientation change so that I can update the views.

I want to update the views whether the orientation is portrait or landscape, so I

2条回答
  •  -上瘾入骨i
    2020-12-31 09:59

    You need to add notification observer something like

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
    

    and add the method

    - (void) didRotate:(NSNotification *)notification
    {   
          UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    
           if (orientation == UIDeviceOrientationLandscapeLeft)
          {
            NSLog(@"Landscape Left!");
          }
    }
    

提交回复
热议问题