简体   繁体   English

如何旋转两个UIView?

[英]How to rotate two UIView's?

I created a app with the iOS 4.1 SDK. 我使用iOS 4.1 SDK创建了一个应用程序。

In this app I did the following: I add two UIView's as subview to the Window of the Application. 在此应用程序中,我执行了以下操作:我将两个UIView作为子视图添加到应用程序的窗口。 One view is a navigationcontrollerview and the other is a view that displays advertisement. 一个视图是navigationcontroller视图,另一个视图是显示广告的视图。 The user can then navigate trough the app will the ads are displayed uninterrupted. 然后,用户可以浏览应用程序,广告将不间断地显示。

Now comes the problem: I wanted to add the option to rotate the device from portrait to landscape and back. 现在出现了问题:我想添加选项以将设备从纵向旋转到横向再旋转。 The problem is only the first view (in my case the navigationcontrollerview) is rotated without problem. 问题是只有第一个视图(在我的情况下是navigationcontrollerview)旋转时没有问题。 The second view is never rotated. 第二个视图永远不会旋转。 Documentation from Apple confirms that this is the default behavior. Apple的文档确认这是默认行为。

So, how do I get my second view rotated? 那么,如何旋转第二个视图? Do I need to restructure my application? 我需要重组我的应用程序吗? And why is the second view never rotated? 为什么第二个视图永远不会旋转? That doesn't make any sense to me. 这对我来说毫无意义。

Are you just adding the second view (the one that doesn't rotate) as a plain UIView? 您是否只是将第二个视图(不旋转的视图)添加为纯UIView? If so, try adding it after containing it within a UIViewController class. 如果是这样,请尝试将其包含在UIViewController类中之后添加。 I had the same issue in my app not so long ago. 不久前,我的应用程序中遇到了同样的问题。 instead of [window addSubview:sampleView], I did [window addSubview:[sampleViewController view]]; 而不是[window addSubview:sampleView],我做了[window addSubview:[sampleViewController view]]; where sampleViewController subclasses UIViewController. 其中sampleViewController子类化UIViewController。

In general, always use corresponding view controllers and contain views in them and then add subviews to avoid these issues. 通常,请始终使用相应的视图控制器并在其中包含视图,然后添加子视图以避免这些问题。

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

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