我想知道在TextView上使用resignFirstResponder
时,有什么方法可以减缓iOS应用中原生键盘的消失。键盘下降得太快,我希望它变慢。这可能吗?
修改 我的背景是这样的: 我在当前视图的顶部添加了一个新视图,因此,我的键盘暂时消失。 这就是我的代码的样子:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *tmpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[tmpButton setTitle:@"Tap me" forState:UIControlStateNormal];
[tmpButton sizeToFit];
[tmpButton addTarget:self action:@selector(btnTestClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tmpButton];
}
- (void) btnTestClicked{
[tmpText resignFirstResponder];
}
我也有类似的视图层次结构:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.windowLevel = UIWindowLevelStatusBar + 1;
return YES;
}
该应用程序非常简单,但键盘消失得非常快,而不是像我没有任何其他视图时那样。
答案 0 :(得分:4)
简单,我认为:
- (void)btnTestClicked {
[UIView animateWithDuration:2.0 animations:^(void){
[tmpText resignFirstResponder];
} completion:^(BOOL finished) {
//Do something
}];
}
答案 1 :(得分:2)
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[self.view endEditing:YES];
}completion:nil];