Can I change the keyboard orientation?

两盒软妹~` 提交于 2020-01-11 06:50:08

问题


For example I turn off autorotation with this code

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return NO;
}
-(BOOL)shouldAutorotate
{
    return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return 0;
}

And my buttons, labels, textFields and other object can rotate according to the current orientation of the device. But keyboard doesn't want to rotate=/ How i can rotate keyboard or i can't. Who knows? Please help) http://www.pictureshack.ru/images/8145_Snimok_ekrana_05_11_2013_18_55_00_s_Simulyatora_iOS.png


回答1:


Keyboard orientation is same as Status Bar orientation.

in image, all your button and text orientation not in orientation of Status Bar.

try following code

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}



回答2:


OK. Decision proved to be a simple. In my method where i checked device orientation, i add this code and it's working.

    if (deviceOrientation == UIDeviceOrientationPortrait){
         [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
    }
    else if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown){
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown animated:NO];  
    }
    else if (deviceOrientation == UIDeviceOrientationLandscapeLeft){
         [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
    }
    else if (deviceOrientation == UIDeviceOrientationLandscapeRight){
         [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
}

Hope this helps to someone!)



来源:https://stackoverflow.com/questions/19810036/can-i-change-the-keyboard-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!