简体   繁体   中英

iPhone interface orientation statement not working in OS 3.0?

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...");

}

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];

如果要测试是否输入了此块,请尝试在textviewheight分配之前尝试一条日志语句(如果在赋值错误的情况下提前退出,则不行)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM