Keyboard is upside down in UIViewController - iphone

I'm trying to get my app updated to work with the new iPhone 5, and some of my views are dropping the keyboard down from the top of the view instead of the bottom. Here's an image to better illustrate:
This worked before iOS 6.0, so I'm guessing it must be something in the new API that is causing this bug to shine. I am using the following code to support orientations in the UIVeiwController:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
Has anyone else seen a similar problem? Thanks!

I have tried to replicate your issue but it works good for me on iOS6. My suggestion might be not very helpful but review that delegate, the synthesize and all the features match.

I found the answer at this question. My problem was fixed by changing one line of code where I was setting up my root UI view controller.
Changing this line:
[window addSubview:viewController.view];
to this:
[window setRootViewController:viewController];

Andrew, I also find that the method shouldAutoROtateToInterfaceOrientation was deprecated in iOS 6.
Anyways, I saw you solved your issue.

Related

rotation issue in ios 6

I've looked everywhere, Yet I cant find a solution for this annoying rotation issue in iOS 6.
for some reason, I cant get the rotation methods in iOS 6 to work. they are not even called.
for example:
if I want to keep a view in portrait mode in iOS 5, I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I learned that the new method in iOS 6 should be:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
I've also try to add:
-(BOOL)shouldAutorotate
{
return NO;
}
but it dosent work at all.
please help!
If you have all that it should be as simple as setting the supported orientations in the Info.plist as well as in your controllers. You can do this through the Summary tab on your project target.

iOS 6 Crashes on Device Rotation [duplicate]

This question already has answers here:
Closed 10 years ago.
THIS IS NOT A DUPLICATE QUESTION. A final working solution has NOT been provided yet. Please do not CLOSE this question until I have accepted an answer or found and provided my own solution for this. Thanks!
==================================================================
Using Xcode 4.5.1, I have a tab-bar app with 5 tabs in it. Each tab contains a UINavigationController. The entire App thus needs to be viewed in Portrait mode with the exception of one sole ViewController - a "modal" VC that opens in full screen and that's intended to be viewed in Landscape mode.
This worked perfectly well in iOS5 - I simply used the following code in that one particular ViewController:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
But now the App crashes, and gives this error:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',
reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
Any suggestions?
Kindly check the What version xcode you used.
You used XCODE 4.5: shouldAutorotateToInterfaceOrientation delegate Depreciated.
You use following lines in your project.
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
You need to use this to avoid iOS6 crash..
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown; //Getting error here? then update ur xcode to 4.5+
}
#endif
Remember one thing. In iOS 6
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
is deprecated.
You cannot use it in iOS 6. For supporting different interface orientation in viewControllers of a UINavigationController you need to subclass the UINavigationController or make a Category of it.
Code looks OK. it Should not have crashed for just that methods.
problem coud be in another part of code.
However ,here i would like to tell you.
Above shouldAutorotateToInterfaceOrientation methods orientation methods has deprecated in iOS 6.
if you want to know more how to fix orientation issue
you should take a look of this

shouldAutoRotate not getting called [duplicate]

I've been writing my Universal application in portrait mode,
and now after about 15 nib files, many many viewCotnrollers,
I'd like to implement the shouldAutorotateToInterfaceOrientation and design some screens in Landscape mode.
adding :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
to ALL of my viewControllers, does not do the work.
During Debug, i see that this method is called, but it just won't work! not in the simulator, not in the device, not in Iphone, not in Ipad!
i've searched some answers in the forum, and saw some advises to use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown );
}
Didn't worked either,
adding:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
and
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
to my viewDidLoad and viewDidUnload respectively didn't worked either.
I'm lost.. Any help will do!
just one more info... all my Views are of type UIControl, as i needed the TuchUpInside to work.
Appriciate your help.
Make sure all of your parent views have autoresizesSubviews = YES. You may need to do this in code if you haven't set springs and struts in IB for all of your views.
Quoting the Interface Builder User's Guide:
Important: In a Cocoa nib file, if you
do not set any springs or struts for
your view in Interface Builder but
then do use the setAutoresizingMask:
method to add autosizing behavior at
runtime, your view may still not
exhibit the correct autoresizing
behavior. The reason is that Interface
Builder disables autosizing of a
parent view’s children altogether if
those children have no springs and
struts set. To enable the autosizing
behavior again, you must pass YES to
the setAutoresizesSubviews: method of
the parent view. Upon doing that, the
child views should autosize correctly.
A couple other things to be aware of:
A UINavigationController will only autorotate if its root view controller is also set to autorotate.
A UITabBarController will only autorotate if all of its view controllers are set to autorotate.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIInterfaceOrientation des=self.interfaceOrientation;
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) //iPad
{
if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown)//ipad-portairait
{
}
else//ipad -landscape
{
}
}
else//iphone
{
UIInterfaceOrientation des=self.interfaceOrientation;
if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown) //iphone portrait
{
}
else //iphone -landscape
{
}
}
return YES;
}
Which iOS are you building for? It was deprecated in iOS 6.0. (You should override the supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation methods instead.)
Also you can call shouldAutorotate on the UIViewController class:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/shouldAutorotate
Ensure you have checked the Supported Interface Orientations within the "Summery" tab of the project settings (Select the project name in the 'Project Navigator' at the very top).
If you have not selected the orientations you want to use here, then the simulator/iphone will not allow the screen to change orientation.
I had this problem but it worked in iOS6 but not iOS5. Turns out I had a view in my storyboard that I hadn't made a viewcontroller class for yet.
...and last but not least, make sure you haven't activated the setting "Portrait Orientation Locked" on your test device (of course doesn't apply to the simulator), this will disable rotating in any app no matter what shouldAutorotateToInterfaceOrientation returns.

How to restrict my app to landscape mode?

I have my iPad application created using the SplitView template.
I wonder what is the best way to restrict my application to landscape mode?
I have tried overriding shouldAutorotateToInterfaceOrientation: method in DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
but 4.2 GM is still buggy and it fails to show the controller view. What other choices do I have?
Thanks in advance.
UPDATE1
I have already filed a bug report:
Bug ID #8620135
My app is almost finished and I have to find a work-arround since I don't think they are going to solve this before 4.2 officially comes out (GM is already out!)
In order to recreate the bug, just use SplitView template and override above method in any of the UIViewControllers (RootViewController or DetailViewControllers)
UPDATE2
I have found a work-around. (See UPDATE3 for the complete work-around)
Set UISupportedInterfaceOrientations only to support Landscape , this will force the app to start in landscape mode allowing DetailViewController to start correctly(hence shown correctly)
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
But if you rotate the device, it turns Portrait mode!!!, so is still necessary to override shouldAutorotateToIntercafeOrientation: as above
Discussion:
If this wouldn't be a bug I would expect a warning or execution error, exception or something when starting the app in a orientation that is not supported by the view controller. Besides, why only DetailViewController does not show? If this would be specification, then RootViewController should also fail to load then. Don't you think?
thanks for you help... ;)
UPDATE3
After further tests I have realized that above work-around does not work in some cases. For example when starting the app when the device is in landscape won't work!.
The real problem seems to be that in iOS4.2GM UISplitViewController needs all its controllers have all rotations to be available at its load time. So is necessary to trick him so it loads in Landscape mode and then not allow him to rotate its view controllers.
So here is the new work-around for this annoying iBug.
Step1:
Set Info.plist like so:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Step2
Set a new flag in DetailViewController.m or .h (from SplitView Template)
BOOL lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//WORK-ARROUND: Bug ID# 8620135.
if (lockRotation) {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}else{
return YES;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//set NO here since this is called before shouldAutorotateToInterfaceOrientation method is called
lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
}
- (void)viewDidAppear:(BOOL)animated {
//set YES as soon as possible, but after shouldAutorotateToInterfaceOrientation method was called
lockRotation = YES; //WORK-ARROUND: Bug ID# 8620135.
[super viewDidAppear:animated];
}
IMPORTANT NOTE:
Please note that this bug only appears when the UISplitViewController is loaded and not everytime
the its view appears. Hence, to see this bug make sure the app was terminated before.
I asked a question with a bounty of 500 that seems to be the same thing you're facing.
From my limited experience it is much easier to make a landscape-only iPhone app than a landscape-only iPad app. I'm not sure why there is any difference, but the steps Apple says to take to make it landscape-only do not work on their own.
Try this (it works):
-(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation {
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
}
else
{
return NO;
}
}
Check out this iPhone app in landscape mode, if you haven't already. I was going to suggest simply adding UISupportedInterfaceOrientations to your Info.plist and specifying the two landscape orientations. But, apparently, this is not sufficient, according to answers to cited question.
I believe this is a BUG, I faced this problem also. It is something to do with
UIInterfaceOrientationLandscapeLeft
To replicate this situation:
1) Create a new iPad project using UISplitViewController template
2) Edit info.plist
Supported interface orientations
-Landscape (left home button)
-Landscape (right home button)
3) DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// return YES;
NSLog(#"RotateToInterface:[%d] vs LandscapeLeft[%d]", interfaceOrientation, UIInterfaceOrientationLandscapeLeft);
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}
4) Run it....You will see a blank black view. and no matter how you turn. "UIInterfaceOrientationLandscapeLeft" never detected.
By the way, nacho4d's adding BOOL check work-around is working. Thumbs UP :)

shouldAutorotateToInterfaceOrientation doesn't work

I've been writing my Universal application in portrait mode,
and now after about 15 nib files, many many viewCotnrollers,
I'd like to implement the shouldAutorotateToInterfaceOrientation and design some screens in Landscape mode.
adding :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
to ALL of my viewControllers, does not do the work.
During Debug, i see that this method is called, but it just won't work! not in the simulator, not in the device, not in Iphone, not in Ipad!
i've searched some answers in the forum, and saw some advises to use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown );
}
Didn't worked either,
adding:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
and
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
to my viewDidLoad and viewDidUnload respectively didn't worked either.
I'm lost.. Any help will do!
just one more info... all my Views are of type UIControl, as i needed the TuchUpInside to work.
Appriciate your help.
Make sure all of your parent views have autoresizesSubviews = YES. You may need to do this in code if you haven't set springs and struts in IB for all of your views.
Quoting the Interface Builder User's Guide:
Important: In a Cocoa nib file, if you
do not set any springs or struts for
your view in Interface Builder but
then do use the setAutoresizingMask:
method to add autosizing behavior at
runtime, your view may still not
exhibit the correct autoresizing
behavior. The reason is that Interface
Builder disables autosizing of a
parent view’s children altogether if
those children have no springs and
struts set. To enable the autosizing
behavior again, you must pass YES to
the setAutoresizesSubviews: method of
the parent view. Upon doing that, the
child views should autosize correctly.
A couple other things to be aware of:
A UINavigationController will only autorotate if its root view controller is also set to autorotate.
A UITabBarController will only autorotate if all of its view controllers are set to autorotate.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIInterfaceOrientation des=self.interfaceOrientation;
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) //iPad
{
if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown)//ipad-portairait
{
}
else//ipad -landscape
{
}
}
else//iphone
{
UIInterfaceOrientation des=self.interfaceOrientation;
if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown) //iphone portrait
{
}
else //iphone -landscape
{
}
}
return YES;
}
Which iOS are you building for? It was deprecated in iOS 6.0. (You should override the supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation methods instead.)
Also you can call shouldAutorotate on the UIViewController class:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/shouldAutorotate
Ensure you have checked the Supported Interface Orientations within the "Summery" tab of the project settings (Select the project name in the 'Project Navigator' at the very top).
If you have not selected the orientations you want to use here, then the simulator/iphone will not allow the screen to change orientation.
I had this problem but it worked in iOS6 but not iOS5. Turns out I had a view in my storyboard that I hadn't made a viewcontroller class for yet.
...and last but not least, make sure you haven't activated the setting "Portrait Orientation Locked" on your test device (of course doesn't apply to the simulator), this will disable rotating in any app no matter what shouldAutorotateToInterfaceOrientation returns.