更改iOS7中的导航工具栏位置?

时间:2013-09-27 18:43:32

标签: ios6 uinavigationcontroller ios7 uitoolbar uiviewanimation

有谁知道如何更改iOS7中工具栏的位置?我的工具栏上有一个文本字段,在编辑过程中键盘出现时需要查看。

在iOS6中,我只是为工具栏框架设置了动画并更改了工具栏的位置,但它似乎在iOS7中不起作用。有没有办法在iOS7中执行此操作?

- (void)textFieldDidBeginEditing:(UITextField *)textField
{   
     [UIView animateWithDuration:0.25
                           delay:0.0
                         options:UIViewAnimationOptionCurveEaseIn
                      animations:^{
                           [self.navigationController.toolbar 
                                  setFrame:
                             CGRectMake(0, self.view.bounds.size.height - 172, 320, 44)];
                      }
                      completion:nil];
}

1 个答案:

答案 0 :(得分:0)

我明白了。我在动画中添加了另一个按钮,然后尝试更改完成块中的工具栏框架而且工作正常!另一个按钮就是在键盘外面按下resignFirstResponder。我不知道为什么会这样,但我并不抱怨:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{   
    self.done = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 0)];
    self.done.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    [self.done  addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationController.view addSubview:self.done];

    [UIView animateWithDuration:0.25
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{
                         [self.done setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 172 + 20)];
                     }
                     completion:^(BOOL finished) {
                         [self.navigationController.toolbar setFrame:CGRectMake(0, self.view.bounds.size.height - 172 + 20, 320, 44)];
                     }
     ];
}

我注意到的另一件事是我无法更改工具栏的半透明属性。当我试图实施时:

self.navigationController.toolbar.translucent = YES;

或当我尝试实施时:

self.navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;

它导致动画完成块代码无效。我不确定这是一个错误还是什么?