iPhone视图控制器风景/肖像旋转问题
我试图为我的应用程序的不同子模式实施强制肖像/风景取向。为此,我有一个UINavigationController作为根控制器和每个子模式具有它是是iPhone视图控制器风景/肖像旋转问题
@interface iosPortraitViewController : UIViewController
或
@interface iosLandscapeViewController : UIViewController
与任一
-(BOOL)shouldAutorotate;
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
-(NSUInteger) supportedInterfaceOrientations;
重载一个和自己的视图控制器根据每个人的方向类型正确设置。例如iosLandscapeViewController :: supportedInterfaceOrientations返回UIInterfaceOrientationMaskLandscape。
当应用程序中的子模式发生变化时,相应的视图控制器将使用present/dismissViewController呈现在根视图控制器上,并强制重定向并调用重载视图控制器类中的函数并定位自身因此。
我的问题是,当我们切换到横向时,子模式视图的框架从它应该在的屏幕的左上角偏移(它是显示背景图片的全屏视图)。
为了进行调试,如果我改变该子模式视图控制器到iosPortraitViewController视图的信息是:
size = 480.000000 320.000000
bounds = 0.000000 0.000000 480.000000 320.000000
frame = 0.000000 0.000000 480.000000 320.000000
centre = 240.000000 160.000000
user interaction enabled = 1
hidden = 0
transform = 1.000000 0.000000 0.000000 1.000000 : 0.000000 0.000000
当在横向模式,这是它需要的视图信息:
size = 480.000000 320.000000
bounds = 0.000000 0.000000 480.000000 320.000000
frame = 80.000000 -80.000000 320.000000 480.000000
centre = 240.000000 160.000000
user interaction enabled = 1
hidden = 0
transform = 0.000000 -1.000000 1.000000 0.000000 : 0.000000 0.000000
80,-80起源框架的是我遇到的问题 - 它应该是0,0。 (如果任何人都可以指出它是如何得到80,-80也是值得赞赏的 - 我可以看到它的X,但不是Y)。
另请注意,框架中的w和h如何交换,变换是旋转变换 - 从阅读中,我猜UIWindow(它始终处于纵向模式)已将此应用于视图变换根视图控制器?
我能做些什么来解决这个问题?我需要视图控制器视图的框架位于正确的位置(即原点为0,0)。我尝试了对它进行硬编码,但它似乎没有工作,反正它不是一个很好的解决方案 - 我非常理解正在发生的事情以及如何正确解决它。
谢谢!
:-)
为了支持备用景观界面,你必须做到以下几点:
- 实现两个视图控制器对象。一个呈现仅肖像界面,另一个呈现仅景观界面。
- 注册UIDeviceOrientationDidChangeNotification通知。在您的处理程序方法中,根据当前设备方向呈现或取消备用视图控制器。
从苹果公司的指导Creating an Alternate Landscape Interface
从导另外:
@implementation PortraitViewController
- (void)awakeFromNib
{
isShowingLandscapeView = NO;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
!isShowingLandscapeView)
{
[self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];
isShowingLandscapeView = YES;
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
isShowingLandscapeView)
{
[self dismissViewControllerAnimated:YES completion:nil];
isShowingLandscapeView = NO;
}
}