Reputation: 3682
I am creating a custom keyboard and I don't want to support for landscape mode. So, if a user rotates device to landscape mode then the keyboard must still be in portrait mode. I have tried the following methods:
-(BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
and
-(void)viewDidLoad{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPotrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
But none of the methods works. The only method fires while rotating the device is this:
-(void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
Here I'm getting the current view size after rotation. But how do I stop the rotation? Any help will be appreciated.
Upvotes: 1
Views: 562
Reputation: 856
Could you please try the same on viewDidAppear
-(void)viewDidAppear:(BOOL)animated{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPotrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
Upvotes: 0
Reputation: 1130
If you are creating a custom keyboard for your app itself, then It should be controllable.
Ideally the orientation is inherited from the last heirarchial or the current visible view Controller of the app.
But if you are creating a third party keyboard application then Custom keyboard is kind of app overlayed on other app where as the orientation is still inherited from the app which is in the keywindow currently. I think custom keyboard cannot be limited to a particular orientation so that user feels convienient in using all the apps with that custom keyboard.
Upvotes: 1