如何在iPhone中更改方向时更改viewcontroller的视图? [英] How to change view of the viewcontroller when change the orientation in iPhone?

查看:140
本文介绍了如何在iPhone中更改方向时更改viewcontroller的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发支持2种方向的iPhone应用程序。我有这个视图控制器的2个UIView文件。我需要根据设备接口方向将相应的UIView文件设置到视图控制器。你能指导我如何改变方向吗?

I'm developing an iPhone application which supports 2 orientations. I have 2 UIView files for this view controller. I need to set corresponding UIView file to the view controller according to the device interface orientation. Can you guide me on how to change the orientation?

推荐答案

为什么你要为两个方向使用两个视图?您可以设置控件的autoresizemask属性,如果纵向和横向两种模式具有相似的控件,则可以在同一位置显示。否则,则需要使用在

Why do you want to use two views for both orientation? You can set autoresizemask properties of controls, if portrait and landscape both mode has similar control to be show at same place. Otherwise, you need to use two views in

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

或者你可以收到UIDevice的通知

or you can have notification of UIDevice

 UIKIT_EXTERN NSString *const UIDeviceOrientationDidChangeNotification;

- (void)beginGeneratingDeviceOrientationNotifications;      // nestable
- (void)endGeneratingDeviceOrientationNotifications;

这篇关于如何在iPhone中更改方向时更改viewcontroller的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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