3

I wonder is there any way to slow down the disappearance of a native keyboard in an iOS app when using resignFirstResponder on a TextView. The keyboard is going down too fast and I want it to go slower. Is that possible?

EDIT: My context is this: I add a new view on top of the current view and because of this, my keyboard disappears momentarily. That's how my code looks:

- (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];
}

I also have the view hierarchy like that:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window.windowLevel = UIWindowLevelStatusBar + 1;
    return YES;
}

The app is real simple but the keyboards disappears very fast, not like when I don't have any other views.

Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120

2 Answers2

4

Simple, I think:

- (void)btnTestClicked {
        [UIView animateWithDuration:2.0 animations:^(void){
            [tmpText resignFirstResponder];
        } completion:^(BOOL finished) {
              //Do something
        }];    
    }
shim
  • 9,289
  • 12
  • 69
  • 108
LE SANG
  • 10,955
  • 7
  • 59
  • 78
2
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    [self.view endEditing:YES];
}completion:nil];
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74