2012-09-06 55 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

相关问题