更改iOS7中的UINavigation工具栏位置?(Change the UINavigation toolbar position in iOS7?)

编程入门 行业动态 更新时间:2024-10-23 14:25:56
更改iOS7中的UINavigation工具栏位置?(Change the UINavigation toolbar position in iOS7?)

有谁知道如何更改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?

更多推荐

本文发布于:2023-08-04 10:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1414820.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工具栏   位置   UINavigation   toolbar   Change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!