切换到另一个视图时隐藏键盘

发布于 2024-11-25 04:01:23 字数 1330 浏览 3 评论 0原文

我有 2 个视图,登录和注册。

我做了 [currentTextField resignFirstResponder];在我导航到另一个视图之前。

问题是,键盘只有在切换视图后才会隐藏。因此,在另一个视图上触发了 KeyboardDidShow 方法,这导致了混乱。

2011-07-19 18:55:33.315 Prime Taxi Booking[601:207] Login view appear // lauched app
2011-07-19 18:55:34.952 Prime Taxi Booking[601:207] Login Keyboard appear // starts typing
2011-07-19 18:55:37.033 Prime Taxi Booking[601:207] Register view appeared // navigation
2011-07-19 18:55:37.036 Prime Taxi Booking[601:207] Login view disappear
2011-07-19 18:55:37.360 Prime Taxi Booking[601:207] Register Keyboard disappear // ?? how do I make this to disappear login keyboard instead?

我想知道为什么当我明确地将它放在它上面时,它在切换视图后才辞职。

-(IBAction) registerButton:(id) sender
{
[currentTextField resignFirstResponder];
Registers *registerview = [[Registers alloc] initWithNibName:nil bundle:nil];
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
                       forView:self.view.superview
                         cache:YES];

[UIView commitAnimations];

[self presentModalViewController:registerview animated:YES];

//[self.view addSubview:registerview.view];

}

I have 2 views, login and register.

I did [currentTextField resignFirstResponder]; before I navigates to the other view.

The problem is, the keyboard is only hidden after it switched view. Which thus fired the keyboardDidShow method on the other view which messes stuff up.

2011-07-19 18:55:33.315 Prime Taxi Booking[601:207] Login view appear // lauched app
2011-07-19 18:55:34.952 Prime Taxi Booking[601:207] Login Keyboard appear // starts typing
2011-07-19 18:55:37.033 Prime Taxi Booking[601:207] Register view appeared // navigation
2011-07-19 18:55:37.036 Prime Taxi Booking[601:207] Login view disappear
2011-07-19 18:55:37.360 Prime Taxi Booking[601:207] Register Keyboard disappear // ?? how do I make this to disappear login keyboard instead?

I wonder why did it only resignFirstResponder after switching views when I clearly placed it above it.

-(IBAction) registerButton:(id) sender
{
[currentTextField resignFirstResponder];
Registers *registerview = [[Registers alloc] initWithNibName:nil bundle:nil];
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
                       forView:self.view.superview
                         cache:YES];

[UIView commitAnimations];

[self presentModalViewController:registerview animated:YES];

//[self.view addSubview:registerview.view];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

春花秋月 2024-12-02 04:01:23

您可以在进入第二个视图之前延迟一些,以便键盘会隐藏。 try [self PerformSelector: withObject: afterDelay:0.35];//在调用此退出当前文本字段之前传递像@selector(displaySecondView)这样的选择器。

you can put some delay before going to second view so that keyboard will hide. try [self performSelector: withObject: afterDelay:0.35];//Pass the selector like @selector(displaySecondView) before calling this resign current textfield.

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