【问题标题】:UIToolBar and iPhone Interface Orientation IssueUIToolBar 和 iPhone 界面方向问题
【发布时间】:2009-11-28 23:42:04
【问题描述】:

我正在 iPhone 中开发一个应用程序。一种视图支持纵向和横向方向。对于两个方向,我都有两个单独的视图。此视图的顶部有一个UIToolbar

问题是当我将视图从横向更改为纵向时,顶部的UIToolbar 消失了。我希望toolbar 在旋转回纵向时回到原来的位置。

这就是我在我的程序中所做的:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {    
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
    {
        self.view = self.portrait;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
        self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);  
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view = self.landscape;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
        self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
    }
    else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        self.view = self.portrait;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
        self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        self.view = self.landscape;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = 
        CGAffineTransformMakeRotation(degreesToRadian(90));
        self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
    }
}

我不知道我在这里错过了什么?任何帮助将不胜感激。

【问题讨论】:

    标签: iphone orientation uitoolbar


    【解决方案1】:

    在界面生成器中,选择工具栏,点击command-3;这会调出标尺/对齐控制菜单。

    在 Autsizing 部分下,默认情况下工具栏只与左右和中心耦合。不至于TOP。选择顶部的“我”。现在工具栏相对于视图的顶部停靠,并且在旋转过程中不会被推开。

    我敢肯定也有对应的代码

    【讨论】:

    • 也可能是某些其他视图没有正确锚定(在自动调整大小中),并且正在工具栏顶部绘制自身。
    【解决方案2】:

    如果你只想让你的视图可旋转,那么实现就足够了

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

    在你的 viewCountroller 类中

    【讨论】:

    • 另外,您还需要在 Interface Builder 的布局选项卡上设置锚点/拉伸设置。
    • 我有两个视图,我想在纵向和横向模式下交换它们。纵向视图顶部有一个工具栏,在第一次启动时看起来很好。但是当我改变方向并将其设置回纵向时,工具栏就会消失。
    【解决方案3】:
    self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);  
    

    这里的问题是你的高度是 480。但它应该是 460。所以你现在的高度多了 20px,这可能会使顶部栏有点偏离屏幕。

    【讨论】:

    • 20px 不会导致整个工具栏消失。 iPhone 的屏幕尺寸为 320x480。
    • 是的。我同意。这就是为什么我说“这可能会使顶部栏从屏幕上移开。” . :)
    • 大家好。感谢您的回复。我尝试设置较小的高度,但工具栏仍然不可见。有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 2010-11-18
    相关资源
    最近更新 更多