iOS: Device orientation on load

前端 未结 16 1945
遥遥无期
遥遥无期 2020-11-28 23:45

It seems that when my app loads, it does not know its current orientation:

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (o         


        
16条回答
  •  悲&欢浪女
    2020-11-29 00:13

    You can do it by inserting the following notification inside

    -(void)viewDidLoad
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkRotation:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
    

    then put the following method inside your class

    -(void)checkRotation:(NSNotification*)notification
    {
        UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
        if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
        {
             //Do your textField animation here
        }
    }
    

    The above method will check the orientation of the status bar of the ipad or iPhone and according to it you make do your animation in the required orientation.

提交回复
热议问题