What is the iPhone's default keyboard animation rate?

前端 未结 7 1858
萌比男神i
萌比男神i 2020-12-13 13:21

A while ago I remember seeing a constant of some kind that defined the animation rate of the Keyboard on the iPhone and I can not for the life of me remember where I saw it.

7条回答
  •  时光说笑
    2020-12-13 13:33

    To add a bit more to what Shaggy Frog wrote. The full implementation would be something like:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardMovement:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardMovement:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    
    
    -(void)keyboardMovement:(NSNotification *)notification{
        if (_numericKeyboardShowing == false){
            [UIView animateWithDuration:[self keyboardAnimationDurationForNotification:notification] delay:0
                            options:UIViewAnimationCurveEaseInOut
                         animations:^ {
                             self.bottomContainerView.center = CGPointMake(self.bottomContainerView.center.x, (self.bottomContainerView.center.y - 218));
                                      }
                         completion:NULL];
    
        _numericKeyboardShowing = true;
       }
       else{
        [UIView animateWithDuration:[self keyboardAnimationDurationForNotification:notification] delay:0
                            options:UIViewAnimationCurveLinear
                         animations:^ {
                             self.bottomContainerView.center = CGPointMake(self.bottomContainerView.center.x, (self.bottomContainerView.center.y + 218));
                         }
                         completion:NULL];
    
        _numericKeyboardShowing = false;
    }
    
    - (NSTimeInterval)keyboardAnimationDurationForNotification:(NSNotification *)notification
    {
        NSDictionary *info      = [notification userInfo];
        NSValue* value          = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
        NSTimeInterval duration = 0;
        [value getValue:&duration];
        return duration;
    }
    

提交回复
热议问题