shouldAutorotateToInterfaceOrientation不起作用 [英] shouldAutorotateToInterfaceOrientation doesn't work

查看:105
本文介绍了shouldAutorotateToInterfaceOrientation不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在以纵向模式编写我的Universal应用程序,
现在在大约15个nib文件之后,许多viewCotnrollers,
我想实现shouldAutorotateToInterfaceOrientation并在Landscape模式下设计一些屏幕。

I've been writing my Universal application in portrait mode, and now after about 15 nib files, many many viewCotnrollers, I'd like to implement the shouldAutorotateToInterfaceOrientation and design some screens in Landscape mode.

添加:

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

到我的所有viewControllers,都不起作用。

to ALL of my viewControllers, does not do the work.

在调试期间,我看到调用了这个方法,但它不起作用!不是在模拟器中,不在设备中,不在Iphone中,而不是在Ipad中!

During Debug, i see that this method is called, but it just won't work! not in the simulator, not in the device, not in Iphone, not in Ipad!

我在论坛中搜索了一些答案,并看到一些建议使用:

i've searched some answers in the forum, and saw some advises to use:

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

也没有用,

添加:

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

我的viewDidLoad和viewDidUnload也分别无效。

to my viewDidLoad and viewDidUnload respectively didn't worked either.

我迷路了..任何帮助都可以!

I'm lost.. Any help will do!

再多一个信息...我的所有视图都是UIControl类型,因为我需要TuchUpInside可以工作。

just one more info... all my Views are of type UIControl, as i needed the TuchUpInside to work.

欢迎你的帮助。

推荐答案

制作确保所有父视图都具有autoresizesSubviews = YES。如果您没有在IB中为所有视图设置弹簧和支柱,则可能需要在代码中执行此操作。

Make sure all of your parent views have autoresizesSubviews = YES. You may need to do this in code if you haven't set springs and struts in IB for all of your views.

引用Interface Builder用户指南:

Quoting the Interface Builder User's Guide:


重要提示:在Cocoa nib文件中,如果你
没有为
设置任何弹簧或struts你在Interface Builder中的视图但
然后使用setAutoresizingMask:
方法在
运行时添加自动调整行为,您的视图可能仍然没有
表现出正确的自动调整
行为。原因是如果
那些孩子没有弹簧和
struts设置,接口
Builder会自动禁用
父视图的子项的自动调整大小。要再次启用自动调整
行为,您必须将
的setAutoresizesSubviews:方法传递给
父视图。这样做,
子视图应该正确自动调整大小。

Important: In a Cocoa nib file, if you do not set any springs or struts for your view in Interface Builder but then do use the setAutoresizingMask: method to add autosizing behavior at runtime, your view may still not exhibit the correct autoresizing behavior. The reason is that Interface Builder disables autosizing of a parent view’s children altogether if those children have no springs and struts set. To enable the autosizing behavior again, you must pass YES to the setAutoresizesSubviews: method of the parent view. Upon doing that, the child views should autosize correctly.

还有其他一些需要注意的事项:

A couple other things to be aware of:


  1. 如果UINavigationController的根视图控制器也设置为自动旋转,则它只会自动旋转。

  1. A UINavigationController will only autorotate if its root view controller is also set to autorotate.

如果UITabBarController的所有视图控制器都设置为自动旋转,则它只会自动旋转。

A UITabBarController will only autorotate if all of its view controllers are set to autorotate.

这篇关于shouldAutorotateToInterfaceOrientation不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆