addsubview + 后 UITextfield 没有响应提交动画

发布于 2024-10-22 00:33:36 字数 1005 浏览 4 评论 0原文

我遇到了一件愚蠢的事情: 我有一个带有导航栏和表格视图的视图。 我的导航栏有一个“搜索”左侧按钮。 当用户按下此“搜索”按钮时,我希望我的表格视图下降,并在导航栏和表格视图之间出现一个专用于搜索的新视图。

  • 我有一个仅实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤者何惧 2024-10-29 00:33:36

嘿,将其添加到最后的 pressSearchBtn 操作中。

[kWTextField 成为FirstResponder];

Hey add this in the pressSearchBtn action towards the end.

[kWTextField becomeFirstResponder];

路还长,别太狂 2024-10-29 00:33:36

或者你可以这样做。在界面生成器中,将文本字段放在视图的正上方,而不是在视图之外。将其放在 (0,0) 处,大小为 (320,31)。然后在工具->属性检查器中检查文本字段的隐藏属性为true。然后在按钮单击中放置此代码。

- (void) pressSearchBtn:(id)sender{ 

    kwtextField.alpha = 0;
    [UIView beginAnimations:@"frame" context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    kwtextField.hidden = FALSE;
    kwtextField.alpha = 1;
    [UIView commitAnimations];
}

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.

- (void) pressSearchBtn:(id)sender{ 

    kwtextField.alpha = 0;
    [UIView beginAnimations:@"frame" context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    kwtextField.hidden = FALSE;
    kwtextField.alpha = 1;
    [UIView commitAnimations];
}
獨角戲 2024-10-29 00:33:36

嘿,我终于为你完成了。

将文本字段放置在界面生成器上的任意位置,将其隐藏在工具中 ->属性检查器。

在 viewDidLoad 方法中执行此操作

- (void)viewDidLoad {

    CGRect frame = CGRectMake(0, -100, 320, 580);

    self.view.frame = frame;

    text.frame = CGRectMake(0, self.view.frame.origin.y, 320, 100);

    [super viewDidLoad];
}

,然后在 btnClick 方法中写入此内容。

-(IBAction) btnClicked: (id) sender
{

    CGRect frame1 = CGRectMake(0, 0, 320, 100); 
    text.hidden = FALSE;
    CGRect frame = self.view.frame;
    [UIView beginAnimations:@"frame" context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    frame.origin.y = 0;
    self.text.frame = frame1;
    self.view.frame = frame;
    [UIView commitAnimations];

}

干杯!!!

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

- (void)viewDidLoad {

    CGRect frame = CGRectMake(0, -100, 320, 580);

    self.view.frame = frame;

    text.frame = CGRectMake(0, self.view.frame.origin.y, 320, 100);

    [super viewDidLoad];
}

then in the btnClick method write this.

-(IBAction) btnClicked: (id) sender
{

    CGRect frame1 = CGRectMake(0, 0, 320, 100); 
    text.hidden = FALSE;
    CGRect frame = self.view.frame;
    [UIView beginAnimations:@"frame" context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    frame.origin.y = 0;
    self.text.frame = frame1;
    self.view.frame = frame;
    [UIView commitAnimations];

}

cheers!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文