English 中文(简体)
Unable to manage orientation with multiple view controllers
原标题:

I m trying to build an iPhone application that has two subviews in the main window. Each view has its own UIViewController subclass associated with it. Also, within each controller s implementation, I ve added the following method:

-(BOOL)shouldAutorotateToInterfaceOrientation:
 (UIInterfaceOrientation)interfaceOrientation {
    return YES;
   }

Thus, I would expect both of the views to respond to changes in orientation. However, this is not the case. Only the first view added to the app s main window responds to orientation. (If I swap the order the views are added, then only the other view responds. In other words, either will work--but only one at a time.)

Why is this? Is it not possible to handle the orientation changes of more than one view?

Thanks!

EDIT: Someone else had this question, so I m copying my solution here:

I was able to address this issue by providing a root view and a root view controller with the method "shouldAutoRotate..." and adding my other views as subviews to the root view. The subviews inherit the auto-rotating behavior, and their associated view controllers shouldn t need to override "shouldAutoRotate..."

最佳回答

Finally going to post my solution here:

Basically, it came down to having a "root" UIViewController. In this, I have the method:

-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
        return YES;
}

I also added the views I wanted to auto-rotate as subviews to this root UIViewContoller s UIView. These subviews also have view controllers but do not override shouldAutorotateToInterfaceOrientation. In fact, adding this method to those view controllers seems to have no effect whatsoever. Only the root view contoller s shouldAutorotateToInterfaceOrientation seems to work and all subviews get rotated properly.

问题回答

You need to override the shouldAutorotateToInterfaceOrientation method on all three controllers you have.

you can try to implement this method in the class, which view contains both your viewController s views





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签