开发者

Strange behavior when switching view controller's view?

I have a UIViewController with IBOutlets linking to several UIViews. Various buttons s开发者_如何学运维witch between the views, but there are issues when I set a new view for the controller. Both the controller and the views are in landscape orientation, but after the first couple of switches some of the views display in portrait mode. What might be causing this?


You should check that all your UIViewControllers implement method shouldAutorotateToInterfaceOrientation. This method tells the operation system in what positions (orientations of screen) the UIViews controlled by that UIViewControllers could be displayed.

If you want all your views be displayed only in landscape orientations, then that method should return YES only for interfaceOrintation == UIInterfaceOrientationLandscapeLeft or interfaceOrintation == UIInterfaceOrientationLandscapeRight. if you want only portrait orientations then interfaceOrintation == UIInterfaceOrientationPortrait.

For example (support only landscape modes) :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

And you should check that in your project settings you set appropriate Supported Device Orientations (also known as Supported interface orientations).


I think you should set the views to landscape mode in IB. If this is already done then I would suggest not changing the view controller's view explicitly. Implement a method, which can change the views.
In more detail:
Set a view as your view controller's view then every other view should be the subview of this view. You can make the change by removing the presented view and adding the new view or another method to implement the view changing is to add all view's in IB as a subview, hide all views then when you would like to change unhide the desired one and hide every other.
I hope you understand my approach, if not then I am here to answer your questions.
This way is easy to implement. :)


Check that you have this method enabled in all views:

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

Also, is it what you see on the simulator or on your device?


This may be a Simulator bug, but try using separate objects of UIViewController for each view, instead of one controller for all views. Personally, I haven't experienced any difficulty with orientation before, but I do things programmatically. I recommend that you do the same (you may NOT need to convert all your program's xib files, but maybe just the one you're having problems with). Just make sure that all UIViewControllers that you're using for that view to have the:shouldAutorotateToInterfaceOrientation set up appropriately and things should work just fine.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜