3

resignFirstResponder我想知道在 TextView 上使用时,有什么方法可以减缓 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;
}

该应用程序非常简单,但键盘消失得非常快,不像我没有任何其他视图时那样。

4

2 回答 2

4

很简单,我认为:

- (void)btnTestClicked {
        [UIView animateWithDuration:2.0 animations:^(void){
            [tmpText resignFirstResponder];
        } completion:^(BOOL finished) {
              //Do something
        }];    
    }
于 2012-12-25T13:57:32.983 回答
2
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    [self.view endEditing:YES];
}completion:nil];
于 2012-12-25T13:48:37.767 回答