屏幕从设备方向旋转和新的UIView

时间:2012-05-03 16:55:15

标签: iphone objective-c rotation screen orientation

当从纵向到横向的屏幕旋转发生时,将最新的UIView置于视图堆栈顶部的应用程序UIWindow界限内最安全,最有效的方法是什么? 此外,从Landscape返回Portrait时,要删除此子视图。

基本上,应用程序创建的大多数是:

  

-UIWindow:

     

- UIView的

     

---所有子视图(包括tabview控制器)

我想创建:

  

-UIWindow:

     

- UIView(新的,置于顶部)

     

- UIView的

     

---所有子视图(由此处的视图控制器触发)

这是错的吗?令人惊讶的是,很少有文档可以帮助您做到这一点。

3 个答案:

答案 0 :(得分:1)

如果您创建一个视图控制器来保存所有子视图,您可以使用将为您调用的旋转功能:

willRotateToInterfaceOrientation:持续时间: 和 didRotateFromInterfaceOrientation:

因此,假设您使用didRotateFromInterfaceOrientation检查

if(UIInterfaceOrientationIsLandscape(orientation))
{
    [yourView removeFromSuperView];
}
else
{
    [self.view addSubView: yourView];
}

答案 1 :(得分:1)

请在此处查看我的回答:https://stackoverflow.com/a/4960988/202451

它应该让你更接近做那样的自定义事情

答案 2 :(得分:0)

我找到了一个有效的解决方案。你能提供更好的产品吗?

    ArtsDayAppDelegate *appDelegate = (ArtsDayAppDelegate*)[[UIApplication sharedApplication] delegate];
    UIView *landscapeView;

    if (!landscapeView) {
        landscapeView = [[UIView alloc] initWithFrame: frame];
    }

    [landscapeView setBackgroundColor:[UIColor blackColor]];
    ..add various views..
    [appDelegate.window.rootViewController.view addSubview:landscapeView];