2012-09-06 52 views
0

我有一個NavBar和ToolBar的簡單項目。我的代碼:解除模態視圖控制器後查看上升

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self.view setBackgroundColor:[UIColor whiteColor]]; 

    [toolBar setBarStyle:UIBarStyleBlack]; 
    [toolBar setTranslucent:YES]; 

    addPhotoItem = [[UIBarButtonItem alloc] initWithTitle:@"Add photo" style:UIBarButtonItemStyleBordered target:self action:@selector(showActionSheet)]; 
    NSArray *itemsArray = @[ addPhotoItem ]; 
    [toolBar setItems:itemsArray]; 
    [toolBar setFrame:CGRectMake(0.0f, self.view.frame.size.height-44.0f, self.view.frame.size.width, 44.0f)]; 
    [self.view addSubview:toolBar]; 

    [navBar setFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 44.0f)]; 
    [navBar setBarStyle:UIBarStyleBlack]; 
    [navBar setTranslucent:YES]; 
    [self.view addSubview:navBar]; 
} 

在我的工具欄中我有一個按鈕,可以打開2個選項的ActionSheet:從相機和庫中獲取圖像。我的代碼:

- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType { 
    self.imagePicker.delegate = self; 
    self.imagePicker.sourceType = sourceType; 
    [self presentModalViewController:self.imagePicker animated:YES]; 
} 

但駁回模態控制器後,我的父視圖上升爲44pt(約)。我該如何解決這個問題?

回答

0

ü不需要設置工具欄的框架,只是在viewDidLoad中

[self.navigationController setToolbarHidden:NO animated:NO]; 

添加此,它會彈出商工具欄,不要手動添加它作爲一個子視圖和u可以添加的UIBarButtonItem爲

self.navigationController.toolbarItems = [NSArray arrayWithObjects:addPhotoItem, nil]; 

和你完成了。

ü可以通過設置參數爲YESsetToolbarHidden

我希望它有助於再次隱藏工具欄。快樂編碼:)

+0

即使我沒有使用UINavigationController應用程序,我可以這樣做嗎? – RomanHouse

+0

不,它只存在於UINavigationController的情況下,你提到你有一個navBar。 –

+0

我有navBar,但我自己添加它 – RomanHouse

相關問題