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

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

问题描述

我一直在以纵向模式编写我的通用应用程序,现在经过大约 15 个 nib 文件,许多 viewCotnrollers,我想实现 shouldAutorotateToInterfaceOrientation 并在横向模式下设计一些屏幕.

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 中为所有视图设置 springs 和 struts,则可能需要在代码中执行此操作.

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 文件中,如果您不要设置任何弹簧或支柱您在 Interface Builder 中的视图,但是然后使用 setAutoresizingMask:添加自动调整行为的方法运行时,您的视图可能仍然没有展示正确的自动调整大小行为.原因是接口Builder 禁用自动调整父视图的孩子完全如果那些孩子没有弹簧支柱设置.启用自动调整大小再次行为,您必须将 YES 传递给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天全站免登陆