0

我有一个用于 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;
    }
}

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

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

4

1 回答 1

1

The solution to this issue was to create a special UIView (called rotationView) and performing all rotation/translations to that UIView instead of directly to the UIToolbar. Then, I can change the toolbar.frame safely without "messing up" the transformations.

于 2012-10-17T16:42:52.253 回答