addsubview + 后 UITextfield 没有响应提交动画
我遇到了一件愚蠢的事情: 我有一个带有导航栏和表格视图的视图。 我的导航栏有一个“搜索”左侧按钮。 当用户按下此“搜索”按钮时,我希望我的表格视图下降,并在导航栏和表格视图之间出现一个专用于搜索的新视图。
我有一个仅实现 UITextfield 的视图控制器:
#import
; @interface serachBox : UIViewController ; { IBOutlet UITextField *kWTextField; } @结尾 我的另一个视图控制器有我的元素(导航栏、表格栏...)。这是我按下搜索按钮时使用的功能:
- (void) pressSearchBtn:(id)sender{ [searchBox.view setFrame:CGRectMake(0, -100, 320, 100)]; CGRect theFrame = self.view.frame; [UIView beginAnimations:@"frame" context:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:self]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; theFrame.origin.y = 100; [self.view addSubview:searchBox.view]; self.view.frame = theFrame; [UIView提交动画]; }
我的问题:我的搜索框视图显示良好,但当我单击它时,她的文本字段没有响应。我测试了一个简单的添加子视图(不执行动画内容)并且它有效。
什么事 ?
I am in troubles with a stupid thing :
I have got a view with a nav bar and a table view.
My nav Bar has a "search" left button.
When the user pushes this "search" button I want my table view to go down and a new view, dedicated to search, to come between my nav bar and my table view.
I have got a view controller that simply implement a UITextfield :
#import <UIKit/UIKit.h> @interface serachBox : UIViewController <UITextFieldDelegate> { IBOutlet UITextField *kWTextField; } @end
My other view controller has my elements (nav bar, table bar ...). Here is the function I use on pushing my search button :
- (void) pressSearchBtn:(id)sender{ [searchBox.view setFrame:CGRectMake(0, -100, 320, 100)]; CGRect theFrame = self.view.frame; [UIView beginAnimations:@"frame" context:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:self]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; theFrame.origin.y = 100; [self.view addSubview:searchBox.view]; self.view.frame = theFrame; [UIView commitAnimations]; }
My problem : my searchbox view appears well but her textfield doesnt respond when I click on it. I tested a simple add subview (without performing the animation stuff) and it works.
What is the matter ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嘿,将其添加到最后的 pressSearchBtn 操作中。
[kWTextField 成为FirstResponder];
Hey add this in the pressSearchBtn action towards the end.
[kWTextField becomeFirstResponder];
或者你可以这样做。在界面生成器中,将文本字段放在视图的正上方,而不是在视图之外。将其放在 (0,0) 处,大小为 (320,31)。然后在工具->属性检查器中检查文本字段的隐藏属性为true。然后在按钮单击中放置此代码。
or you could do this. In the Interface Builder put the textfield right on top of the view and not out of the view. Put it at (0,0) with size (320,31). Then in the tools->attributes inspector check the hidden property of the textfield to true. then in the buttonClick put this code.
嘿,我终于为你完成了。
将文本字段放置在界面生成器上的任意位置,将其隐藏在工具中 ->属性检查器。
在 viewDidLoad 方法中执行此操作
,然后在 btnClick 方法中写入此内容。
干杯!!!
Hey finally I got it done for you.
Put the textfield anywhere on the interface builder, hide it in tools -> attributes inspector.
Do this in you viewDidLoad method
then in the btnClick method write this.
cheers!!!