问题
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