Why won't my UIViewController rotate with the device?

本文详细解释了UIViewController在iOS应用中无法随设备旋转的原因及解决方法,包括但不限于未实现shouldAutorotateToInterfaceOrientation方法、额外视图控制器嵌套、过早释放窗口视图控制器等问题,并提供了针对性的解决方案。

Q:  Why won't my UIViewController rotate with the device?


A: Why won't my UIViewController rotate with the device?

There can be several possible reasons your view controller does not rotate.

The UIViewController class provides the fundamental view-management model for iPhone applications. It provides automatic support for rotating the views of the view controller in response to changes to the orientation of the device. If the autoresizing properties of your view and subviews are properly configured, this behavior is essentially free. Your view controller may not rotate in certain situations if:

  • The view controller does not implement this delegate method:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

    Even if shouldAutorotateToInterfaceOrientation is implemented, you should make sure it returns YES for all the orientations you wish to support. To support all orientations, simply always return YES.

  • The view controller's UIView property is embedded inside UIWindow but alongside an additional view controller.

    You may find a situation where shouldAutorotateToInterfaceOrientation is called once at startup for a given view controller but is never called again when the device is rotated. Because view controllers are tightly bound to the views they manage, they are also part of the responder chain used to handle events. View controllers are themselves descendants of the UIResponder class and are inserted into the responder chain between the managed view and its superview. So it is common practice to have one primary view controller in your application as part of the responder chain. You would typically add one primary view controller such as aUINavigationControllerUITabBarController or a generic UIViewController to your UIWindow. For example, this is done by calling:

    [myWindow addSubview:primaryViewController.view];

    If you add an additional view controller's UIView property to UIWindow (at the same level as your primary view controller) via the following:

    [myWindow addSubview:anotherController.view];

    this additional view controller will not receive rotation events and will never rotate. Only the first view controller added to UIWindow will rotate.

    Note: You may add one view controller's UIView property as a subview to another view controller. In doing so, both views will rotate but the parent view controller remains in charge of determining the supported orientations via its shouldAutorotateToInterfaceOrientation method.

    Note: Keep in mind that UINavigationController and UITabBarController have the capability to manage a "stack" or "list" of view controllers on their own.

  • You have added your view controller's UIView property to UIWindow as a subview, but prematurely released it soon after.

    UIWindow will retain that view, but not the view controller itself. You must not release it prematurely. Declare it as a "retainable" property in yourUIApplicationDelegate subclass.

    Note: UINavigationController and UITabBarController retain your view controllers, so you can release them once they have been added.

  • All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set.

    To make sure that all your child view controllers rotate correctly, you must implement shouldAutorotateToInterfaceOrientation for each view controller representing each tab or navigation level. Each must agree on the same orientation for that rotate to occur. That is, they all should return YES for the same orientation positions.

  • Overriding the -(id)init: or -(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle method without calling super. For the object to be initialized properly, you must call super on any init or initWithNibName method you are overriding for your view controllers.


标题SpringBoot与微信小程序结合的生猪养殖信息化管理系统研究AI更换标题第1章引言介绍生猪养殖信息化管理的研究背景、意义、现状及论文创新点。1.1研究背景与意义阐述生猪养殖信息化管理对提升养殖效率的重要性。1.2国内外研究现状分析国内外生猪养殖信息化管理系统的研究进展。1.3研究方法以及创新点概述SpringBoot与微信小程序结合的技术路径和创新点。第2章相关理论总结SpringBoot框架与微信小程序开发的相关理论。2.1SpringBoot框架理论介绍SpringBoot框架的特点、优势及在Web开发中的应用。2.2微信小程序开发理论阐述微信小程序的开发原理、架构及与后端服务的交互方式。2.3生猪养殖信息化管理理论概述生猪养殖信息化管理的核心概念、流程及需求。第3章系统设计详细介绍基于SpringBoot与微信小程序的生猪养殖信息化管理系统的设计方案。3.1系统架构设计系统的整体架构,包括前端、后端及数据库设计。3.2功能模块设计详细介绍系统的各个功能模块,如养殖管理、数据统计等。3.3数据库设计阐述数据库的设计思路、表结构及关系。第4章系统实现阐述基于SpringBoot与微信小程序的生猪养殖信息化管理系统的实现过程。4.1SpringBoot后端实现介绍后端服务的开发环境、技术选型及实现细节。4.2微信小程序前端实现阐述前端界面的设计、开发及与后端服务的交互。4.3系统集成与测试系统的集成过程、测试方法及结果。第5章研究结果展示系统实现后的效果,包括性能、用户反馈等方面的分析。5.1系统性能分析从响应时间、并发处理等方面分析系统的性能。5.2用户反馈分析收集并分析用户对系统的使用反馈,评估系统的实用性。5.3对比方法分析对比传统生猪养殖管理与信息化管理的差异和优势。第6章结论与展望总结研究成果,提出未来研究方向。6.1研究结论概括系统的主要功能、性能及用户
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值