I want to fix the orientation of the keyboard.
My ViewController supports only Portrait.
If I rotate iPhone, the views in the ViewController does not rotate, but the keyboard appears in landscape.
I want to fix the portrait orientation of keyboard even if I rotate ViewController.
- (BOOL)shouldAutorotate
{
return NO;
}
This code does not work. I hear that UIWindow could be related..
Please give me how to solve this problem.
Set in taget-> General Choose portrait only.
Related
I want to show one view controller in both orientation in iPhone. And when the screen is opening the preferred orientation should be portrait only. Then according to the device orientation it'll rotate. I found some solution and the screen is rotating too. But when I'm entering the screen it is auto rotating to landscape and than I've to manually rotate it to portrait.
Is there a simple solution to this problem?
You should implement preferredInterfaceOrientationForPresentation and
supportedInterfaceOrientations like:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIDeviceOrientationPortrait;
}
//You don't actually need to implement this as UIInterfaceOrientationMaskAllButUpsideDown is the default for iPhone
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
I am only allowing Device Orientation portrait for UIViewControllers being viewed on iPhones through the following code:
- (BOOL)shouldAutorotate
{
NSString *device = [UIDevice currentDevice].model;
return [device rangeOfString:#"iPhone"].location != NSNotFound ? NO : YES;
}
This works fine - when I rotate my iPhone while looking at ViewController A, the view does not rotate. Similarly, when I rotate my iPhone while looking at ViewController B, the view does not rotate. However, when I rotate my iPhone while looking at ViewController A, tap a button that presents ViewController B modally, the show segue animation (Flip Horizontal) is landscape, and ViewController B appears in landscape.
How can I force the segue to be portrait as well and not rotate ViewController B?
In my tests I've found that shouldAutorotate is only one part of the things you have to do to prevent rotation of the device. shouldAutorotate tells the system if it should rotate all the views as soon as someone rotates the device to a different allowed orientation.
My suggestion would be to prevent more orientations other than Landscape (which allows LandscapeLeft and LandscapeRight). And by that I mean you should override supportedInterfaceOrientations in both ViewControllers and tell the app that it should only allow landscape orientations instead of the default (which allows all but upside-down orientation).
Hi I'm using the following code to rotate the orientation of the screen programmatically, without rotating the real device.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown animated:NO];
It rotates everything except the status bar. Can you please tell me, how can I rotate everything on the screen programmatically?
Implement this in your viewController
- (BOOL)shouldAutorotate {
return NO;
}
Your root view controller required to answer NO to shouldAutorotate for your app to respond setStatusBarOrientation:animated method.
I ma trying to lock screen orientation to only landscape orientation when a certain image is still visible, then when the image is hidden, unlock all orientations (targeting iOS 6):
-(BOOL)shouldAutorotate{
if (self.splashImageView.hidden == NO) {
return UIInterfaceOrientationMaskPortrait;//gets called when image is visible
}else{
return UIInterfaceOrientationMaskAll;//gets called when image is hidden
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self shouldAutorotate];
}
As you may notice, shouldAutorotate is called properly but the screen is always supporting landscape orientation even when the image is still visible, is there something missing?
P.S: Please note I am trying to get that to work on a tabbar view controller (a UIViewController subclass).
In your appdelegate you have those two methods.but do you have setting like in your project settings -> go to summary tab and see if orientation is set to only landscape or all.Just try to set those.
I'm wondering why iPad project based on UITabBarController won't autorotate when i specify some of the tab should autorotate in landscape mode and the other will autorotate in landscape and portrait mode.
i've used the
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
for all the UIViewController and specify if landscape return YES; other wise return NO;
In the other hand, if the UIViewController should rotate in landscape and portrait i've justreturn YES;` always.
Thx in advance.
for all the UIViewController you are loading in tabbarcontroller you must return True in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Note:
A tab bar controller will not auto rotate unless ALL the controllers it contains also auto rotate.
from Rotate one UIViewController in UITabBar application -->>
There is no easy way to have only one view in landscape mode, while the others are in landscape, nor an easy way to programmatically switch to landscape mode.
One possible approach would be using a CGAffineTransform to transform your view in your viewWillAppear (i.e., right before the view is shown):
- (void)viewWillAppear:(BOOL)animated; {
//-- Adjust the status bar
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
//-- Rotate the view
CGAffineTransform toLandscape = CGAffineTransformMakeRotation(degreesToRadian(90));
toLandscape = CGAffineTransformTranslate(toLandscape, +90.0, +90.0 );
[self.view setTransform:toLandscape];
}