简体   繁体   English

iPhone接口方向声明在OS 3.0中不起作用?

[英]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. 我有以下代码评估为true,并在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... 但是,如果为OS 3.0编译并运行,则同一行代码的求值结果为true(或大括号)。

I say this because in the debugger (and the log) the lines inside the braces get skipped if I've compiled for 3.0 我之所以这样说,是因为在调试器(和日志)中,如果我针对3.0进行了编译,则大括号内的行会被跳过

This is inside of a textViewDidBeginEditing method on a textView... 这是在textView上的textViewDidBeginEditing方法内部...

Did something change between 2.x and 3.0 relative to how this is handled? 在2.x和3.0之间相对于处理方式是否有所改变? 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. 我不知道为什么,但是这个视图控制器不知道它是自己的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. 我认为这与以下事实有关:它位于UITabBarController内部...以及Apple随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... 不管设备如何旋转,self.interfaceOrientation的底线始终为1(“向上”)。

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. 我通过更改引用并使用MyTabBarController.interfaceOrientation来解决了这一问题,因为TabBarController的“超类”似乎可以可靠地“知道”设备的方向。

(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... (当然,我必须给此类提供MyTabBarController的引用,这是在MyTabBarController将所有UIViewControllers加载到自身中时完成的。)这已经存在于代码中了...

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分配之前尝试一条日志语句(如果在赋值错误的情况下提前退出,则不行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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