【问题标题】:Change the UINavigation toolbar position in iOS7?更改 iOS 7 中的导航工具栏位置?
【发布时间】:2013-09-27 18:43:31
【问题描述】:

有谁知道如何在 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];
}

【问题讨论】:

    标签: ios6 uinavigationcontroller ios7 uitoolbar uiviewanimation


    【解决方案1】:

    我想通了。我在动画中添加了另一个按钮,然后尝试更改完成块中的工具栏框架,它起作用了!另一个按钮就是通过在键盘外按下来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;
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多