Display keyboard without animation

后端 未结 7 1499
感情败类
感情败类 2020-11-29 03:12

Looked intoUIKeyboardAnimationDurationUserInfoKey but I just can\'t find anywhere how to set it to a custom value.

7条回答
  •  失恋的感觉
    2020-11-29 03:26

    UIKeyboardAnimationDurationUserInfoKey is a const string identifier for the dictionary key that holds the animation duration, so there is no way to change it easily.

    One way to make the keyboard appear without animation is to observe the keyboard notifications and disable animation when it's about to appear and then reenable them. This, of course, disables any other animation as well.

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(willShowKeyboard:) 
                                                 name:UIKeyboardWillShowNotification 
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(didShowKeyboard:) 
                                                 name:UIKeyboardDidShowNotification 
                                               object:nil];
    
    - (void)willShowKeyboard:(NSNotification *)notification {
        [UIView setAnimationsEnabled:NO];
    }
    
    - (void)didShowKeyboard:(NSNotification *)notification {
        [UIView setAnimationsEnabled:YES];
    }
    

    and then then the same for UIKeyboardWillHideNotification/UIKeyboardDidHideNotification notifications.

提交回复
热议问题