有谁知道如何更改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]; }Does anyone know how to change the position of the toolbar in iOS7? I have a text field on my tool bar that needs to be viewable when the keyboard appears during editing.
In iOS6 i just animated the toolbar frame and changed the toolbar's position but it doesn't seem to work in iOS7. Is there a way to to do this in 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]; }最满意答案
我想到了。 我在动画中添加了另一个按钮,然后尝试更改完成块中的工具栏框架而且它有效! 另一个按钮就是在键盘外面按下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;它导致动画完成块代码无法正常工作。 我不确定这是一个bug还是什么?
I figured it out. I added another button to the animation and then tried changing the toolbar frame in the completion block instead and it worked! The other button is just there to resignFirstResponder by pressing outside the keyboard. I have no idea why it worked this way but I am not complaining:
- (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)]; } ]; }Another thing I noticed is that I couldn't change the translucent property of my tool bar. When I tried to implement:
self.navigationController.toolbar.translucent = YES;or when I tried to implement:
self.navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;It caused the animation completion block code to not work. I'm not sure if this is a bug or what?
更多推荐
发布评论