如何在iPad中更改UIWindow的方向

时间:2012-07-24 02:24:55

标签: ios

我想创建类似于UIView向下滑动iPad状态栏的内容。但它只能在纵向模式下工作。当我将iPad旋转到横向模式时,UIView仍然以纵向模式滑动。

2 个答案:

答案 0 :(得分:1)

这是因为您要将其添加到窗口

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.

所以试试这个:

UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) 
    window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:myView];    

答案 1 :(得分:-1)

你应该尝试:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

将它放在viewcontroller.m文件中。