How Do I detect the orientation of the device on iOS?

后端 未结 12 915
小鲜肉
小鲜肉 2020-11-30 01:56

I have a question on how to detect the device orientation on iOS. I don\'t need to receive change notifications, just the current orientation itself. This seems to be a rath

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 02:34

    For what You looking for first you have to Get Notification if Orientation Changed! You Can set This Thing in viewDidLoad like

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

    and whenever Orientation of your Device changed OrientationDidChange Called where You can do whatever You Want as Per Orientation

    -(void)OrientationDidChange:(NSNotification*)notification
    {
        UIDeviceOrientation Orientation=[[UIDevice currentDevice]orientation];
    
        if(Orientation==UIDeviceOrientationLandscapeLeft || Orientation==UIDeviceOrientationLandscapeRight)
        {
        }
        else if(Orientation==UIDeviceOrientationPortrait)
        {
        }
    }
    

提交回复
热议问题