【问题标题】:UIToolbar Rotation/AnimationUIToolbar 旋转/动画
【发布时间】:2012-10-16 16:27:18
【问题描述】:

我有一个用于 iPad 应用程序的 UIToolbar,它旨在针对所有方向保持在屏幕顶部。但是,我的 UIToolbar 所属的 UIView 不会旋转。 UIToolbar 确实会旋转,但我无法让旋转按我想要的方式工作...

我不知道如何在不拉伸工具栏的内容(设置缩放变换)或不弄乱变换(设置框架或边界)的情况下更改工具栏的大小。

- (void)updateOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated
{   
    CGAffineTransform toolbarTransform;
    switch(orientation) {
        case UIDeviceOrientationPortrait:
            toolbarTransform = CGAffineTransformIdentity;
            break;

        case UIDeviceOrientationLandscapeRight:
        toolbarTransform = CGAffineTransformMakeTranslation(-768 / 2 + 44 / 2, 768 / 2 - 44 / 2 + 1024 - 768);
        toolbarTransform = CGAffineTransformRotate(toolbarTransform, degreesToRadian(-90));

        break;

        case UIDeviceOrientationLandscapeLeft:
        toolbarTransform = CGAffineTransformMakeTranslation(768 / 2 - 44 / 2, 768 / 2 - 44 / 2);
        toolbarTransform = CGAffineTransformRotate(toolbarTransform, degreesToRadian(90));

        break;

        case UIDeviceOrientationPortraitUpsideDown:
            toolbarTransform = CGAffineTransformMakeTranslation(0, 1024 - 44);
            toolbarTransform = CGAffineTransformRotate(toolbarTransform, degreesToRadian(180));
            break;


        default:
            toolbarTransform = CGAffineTransformIdentity;
            break;
    }

    if(animated)
    {
        [UIView animateWithDuration:.5 animations:^
        {
            self.toolbar.transform = toolbarTransform;
        }];
    }
    else
    {
        self.toolbar.transform = toolbarTransform;
    }
}

这段代码主要是按照我想要的方式定位工具栏,但是我应该如何调整工具栏的大小而不弄乱转换或拉伸工具栏的内容?或者也许我完全错了?

编辑:稍微更新了我的代码。定位是正确的,只是需要以某种方式调整它们的大小......

【问题讨论】:

  • 你应该真正利用 UIViewController 的自动旋转功能,而不是试图手动破解它们。
  • 但我不希望我的主视图自动旋转。如果我能以某种方式将它嵌套在一个可以自动旋转的额外视图中,并且有人可以告诉我如何,我会很好的!我不会一起破解这个,因为我想...... :(
  • 实际上,任何形式的自动旋转都不够,因为其他 UI 元素并不总是与自动旋转将工具栏放入的方向相同。我基本上必须将它“破解”在一起才能达到效果我想要的。

标签: ios uiview rotation uiinterfaceorientation


【解决方案1】:

此问题的解决方案是创建一个特殊的 UIView(称为rotationView),并对该 UIView 执行所有旋转/平移,而不是直接对 UIToolbar。然后,我可以安全地更改 toolbar.frame 而不会“搞砸”转换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 2011-05-20
    • 2013-05-22
    • 2018-11-25
    • 2014-03-04
    • 1970-01-01
    相关资源
    最近更新 更多