7

iOS 7未満のiOSで正常に動作するiPadアプリケーション用のこのコードがあります

UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 75, 44)];

NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];

UIBarButtonItem *composeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(toggleDelete:)];

[buttons addObject:composeButton];

UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

fixedSpace.width = 5;

[buttons addObject:fixedSpace];

UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(touchMe:)];

[buttons addObject:bi];

[tools setItems:buttons animated:NO];

tools.barStyle = -1;

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];

[bi release];
[fixedSpace release];
[composeButton release];
[buttons release];    
[tools release];

この iOS 7 より前の結果は次のとおりです。

ここに画像の説明を入力

同じコードを iOS 7 で実行すると、次の結果が得られます。

ここに画像の説明を入力

何らかの理由で、ボタンは iOS 7 のツールバーの下部に移動されます。

これで、UIBarItem の imageInset プロパティを使用してそれらを再配置できますが、それはハックのように思えます。iOS のバージョンを確認し、iPad が iOS 7 以降を実行している場合にのみ imageInset を実行する必要があるからです。私の質問は、UIToolbar に関連する iOS 7 に固有の何かが欠けていますか? iOS 7 UI Transition Guide を調べましたが、この問題に固有のものは見つかりませんでした。

4

4 に答える 4

5

デザイナー (ストーリーボード) でツールバーを確認します。ツールバーのすべてのボタンに幅が指定されていることを確認してください。同様の問題があり、ストーリーボードのツールバーの各ボタンの幅を指定した後、それがなくなり、iOS 7 のツールバーにボタンが適切に配置されるようになりました。

于 2013-10-18T16:06:51.120 に答える
4

Creating UIToolbar with CGRectZero and setting it's frame after setItems: solved my problem on iOS 7.

UIToolbar *tools = [[UIToolbar alloc] initWithFrame:CGRectZero];
//Create array with items
[tools setItems:buttonsArray animated:NO];
//Setting frame at this moment fixes the issue    
tools.frame = toolbarFrame;
于 2014-01-07T15:27:29.367 に答える
0

iOS7のみでこの問題が発生しました。iOS8 は一般的に完璧に動作します。解決策は、ツールバーの高さが 44.0 であり、デリゲート UIBarPositioning を設定し、項目を上に配置することです。

- (UIBarPosition) positionForBar: (id<UIBarPositioning>) bar {
    return UIBarPositionTop;
}
于 2015-05-03T10:59:34.993 に答える