我正在創建自定義鍵盤,我不想支持橫向模式。因此,如果用戶將設備旋轉到橫向模式,則鍵盤仍然處於縱向模式。我曾嘗試以下方法:禁用自定義鍵盤在ios中的旋轉
-(BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
和
-(void)viewDidLoad{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPotrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
但沒有方法的工作原理。唯一的方法在旋轉設備時觸發:
-(void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
這裏我在旋轉後得到當前視圖大小。但是,我該如何停止輪換?任何幫助將不勝感激。
相同難道這是你在找什麼:http://stackoverflow.com/questions/6941849/disable-orientation-for-keyboard-in-iphone – Ariel
@Ariel:我已經試過了。不工作。 – Poles
我也在製作自定義鍵盤,並使用自動佈局來維護縱向和橫向模式。我和你的情況一樣。 您現在使用自動佈局還是禁用自動佈局? – Ariel