问题
I have the following code which evaluates to true and runs the code inside the braces I rotate to the right (or left) in OS 2.2.1. However the same line of code does not evaluate to true (or go into the braces) if compiled and run for OS 3.0...
I say this because in the debugger (and the log) the lines inside the braces get skipped if I've compiled for 3.0
This is inside of a textViewDidBeginEditing method on a textView...
Did something change between 2.x and 3.0 relative to how this is handled? The non-resizing text field has been noticed by users as a bug I'm trying to fix...
This isn't my code originally and as I look at it, I'm beginning to think I should be implementing some delegate methods for rotation...? But it still bugs me that this statement isn't working...
Thanks in advance for any advice...
if((self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)||(self.interfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
[self setTextViewHeight:107];
NSLog(@"inside if self.interfaceorientation...");
}
回答1:
I don't know why, but this view controller doesn't know it's own interfaceOrientation. I assume it has to do with the fact that it's "inside" a UITabBarController... And the "new way" of handling this that Apple changed with 3.0.
Clarifying comments on that "change" are welcomed!
Bottom line, self.interfaceOrientation was always evaluating to 1 ("Up") no matter how the device was rotated...
I solved this by changing the reference and using MyTabBarController.interfaceOrientation instead, as the TabBarController "superclass" seemed to reliably "know" what the device's orientation was.
(Of course, I had to give this class a reference to MyTabBarController, done when MyTabBarController loads all the UIViewControllers into itself...) This already existed in the code...
Given that reference, the following simple change gave me access to the "true" state of the rotation... and this code ran when expected...
if ((myTabBarController.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (myTabBarController.interfaceOrientation == UIDeviceOrientationLandscapeRight)) {
[self setTextViewHeight:116];
回答2:
Try a log statement before the textviewheight assignment if you want to test if this block is entered (& not if it is exited early by error in assignment)
来源:https://stackoverflow.com/questions/1319305/iphone-interface-orientation-statement-not-working-in-os-3-0