简体   繁体   English

设备方向更改时,自定义UIView不会旋转

[英]Custom UIView does not rotate when device orientation changes

I created a UIView which has two controls on it, a label and an activity indicator (spinning wheel) to display when the device is synchronizing. 我创建了一个UIView,它有两个控件,一个标签和一个活动指示器(旋转轮),以便在设备同步时显示。 As this UIViewController needs to be accessed globally I'm adding it in the app's FinishedLaunching event: 由于这个UIViewController需要全局访问,我在应用程序的FinishedLaunching事件中添加它:

window.AddSubview (navigationController.View); window.AddSubview(navigationController.View); window.AddSubview(SyncSpinner.View); window.AddSubview(SyncSpinner.View); window.MakeKeyAndVisible(); window.MakeKeyAndVisible();

I am overriding the shouldAutoRotate event and returning true to allow rotation of the view with the device. 我重写了shouldAutoRotate事件并返回true以允许使用设备旋转视图。 However, I have been unable to get this view to rotate. 但是,我无法让这个视图旋转。 I've even tried calling teh shouldAutoRotate event from the navigationController's view shouldAutoRotate event, but it still doesn't rotate. 我甚至尝试从navigationController的视图shouldAutoRotate事件中调用teh shouldAutoRotate事件,但它仍然不会旋转。

How do I create a very simple view to use as a status dialog with a label at the top, spinner in the middle, and have this properly rotate? 如何创建一个非常简单的视图用作状态对话框,顶部有一个标签,中间是微调器,并且正确旋转?

Thank you. 谢谢。

A similar thing happend to me. 类似的事情发生在我身上。 I don't know why, but the iPhone only sends the autorotate messages to the newest added view's controller. 我不知道为什么,但iPhone只会将自动旋转消息发送到最新添加的视图的控制器。

A way around it is, to generate notifications and send them to the controller. 绕过它的方法是生成通知并将它们发送到控制器。 Use this block of code in the finished launching method: 在完成的启动方法中使用此代码块:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: viewController selector:@selector(changeOrientation:) name:UIDeviceOrientationDidChangeNotification object:nil];

At least with TweetStation the issue was that I needed to propagate the rotation property all the way from the first UIViewController. 至少在TweetStation上,问题是我需要从第一个UIViewController一直传播rotation属性。 If the toplevel UIViewController did not support rotation, neither did the nested ones. 如果顶层UIViewController不支持旋转,嵌套的也不支持。

In TweetStation I do this with a helper top level class that runs my toplevel tabbar controller: 在TweetStation中,我使用一个帮助顶级类来运行我的顶级tabbar控制器:

http://github.com/migueldeicaza/TweetStation/blob/master/TweetStation/Main.cs#L409 http://github.com/migueldeicaza/TweetStation/blob/master/TweetStation/Main.cs#L409

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

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