1

在我的应用程序中,我有一个 UIToolBar。在纵向模式下,此工具栏位于顶部且水平,但当设备旋转时,此工具栏应转换为垂直工具栏并应放置在左侧。此外,它的子视图,即 5 个 UIBarButtonItems 也应相应放置。

有谁知道这个的解决方案?

我已阅读内容以供参考,但我的工具栏应根据方向自行对齐。我正在使用 iOS 6。

4

2 回答 2

0

There is no built-in vertical menu feature (yet). There are 2 parts in your question:

Vertical UIToolbar:

You may restrict the device orientation and the toolbar will remain at the same location

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

(this will affect all views)

Or you can listen for orientation changes and rotate your toolbar accordingly using its transform property, e.g.

toolbar.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI/2);

Rotated UIBarButtonItem:

If you have rotated the toolbar (case 2 above), items will rotate too. If not, you need to rotate your items. Several post shows how to deal with the fact that as UIBarButtonItem does not extend UIView, it has no transform property (see here). In the end you will have again to listen for orientation changes and rotate the subviews of your toolbar, e.g.

for (UIView *view in toolbar.subviews) {
    view.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI/2);
}

Of course apply the rotation related to your orientation (M_PI/2 or -M_PI/2).

于 2013-01-18T14:02:55.627 回答
0

我遇到了同样的问题,所以我将其子类化UIToolbar并使其成为我想要的样子。这是 GitHub 链接:https ://github.com/fennelouski/NKFToolbar

于 2016-01-28T11:00:37.863 回答