2013-10-30 72 views
1

我有基於導航控制器的應用程序,一個viewcontroller以橫向模式呈現模態圖形。然後,我添加工具欄完成按鈕關閉圖形vc並返回到導航和肖像模式。將工具欄放在屏幕頂部,在底部有正確的陰影

我無法弄清楚如何將工具欄位置上與工具欄的底部正確的陰影圖形視圖 - 控制的頂部。到目前爲止,我有這段代碼將工具欄添加到底部位置,在工具欄頂部有默認陰影。是否允許在屏幕上方顯示工具欄?由於強制定向旋轉的原因,我不能使用導航控制器與圖形vc。平臺僅限iOS7和iPhone。謝謝。

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x, self.view.bounds.size.width - 44.0, self.view.bounds.size.height, 44.0)]; 

UIBarButtonItem *flexibleSpaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 

UIBarButtonItem *doneButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)]; 

toolbar.items = [NSArray arrayWithObjects:flexibleSpaceButtonItem, doneButtonItem, nil]; 

[self.view addSubview:toolbar]; 

回答

1

我覺得你的框架看起來有點怪。您正在從視圖寬度和視圖高度計算y位置。

也許你必須指定工具欄是在使用了UIBarPositioning協議之上。

UIImage *shadow = [toolbar shadowImageForToolbarPosition: UIBarPositionAny]; 
[toolbar setShadowImage:shadow forToolbarPosition:UIBarPositionTopAttached]; 

下一頁編輯:

這是個什麼文件不得不說的iOS的7 UIToolbar:

UIBarPositionTop
指定欄在包含其頂部視圖。
系統將此作爲提示來相應地繪製定向裝飾。例如,任何陰影都將被繪製在條的下面。 UIToolbar的實例不會在iPhone上顯示此位置,但它們可以在iPad上顯示。
Available in iOS 7.0及更高。
宣佈在UIBarCommon.h

也許工具欄並不意味着在頂部使用。但是,你可以簡單地添加陰影與addSubview:

+0

圖形視圖控制器呈現在橫向,因此我認爲寬度和高度互換我希望? –

+0

看到我修正的答案。 – Mundi

+0

我試過這個,xcode抱怨'賦值只讀屬性':( –

1

嘗試實施方法

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar 

UIToolbarDelegate協議。