iOS 7 - Keyboard animation

后端 未结 8 1622
广开言路
广开言路 2020-12-02 09:51

I\'m trying to understand the new keyboard animation in iOS 7.0 on the iPhone 5 Simulator. I want to resize my UITableView when the keyboard appears, but I can\

8条回答
  •  被撕碎了的回忆
    2020-12-02 10:24

    Now I found the solution. The animation starts from the point {0, 920} to {0, 352}. The problem was that the UITableView object started with a size of {160, 568}, so I changed the size of the UITableView to {160, 920} before the animation was started.

    Concerning to the unknown animation curve, I just set the parameter to animationCurve << 16 to convert it from a view animation curve to a view animation option.
    The value is not equal to the linear, ease in, ease out and ease inout animation curve.

    Here is my code:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(_keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    

    and:

    - (void)keyboardWillShow:(NSNotification *)aNotification {
        NSDictionary *userInfo = aNotification.userInfo;
    
        //
        // Get keyboard size.
    
        NSValue *beginFrameValue = userInfo[UIKeyboardFrameBeginUserInfoKey];
        CGRect keyboardBeginFrame = [self.view convertRect:beginFrameValue.CGRectValue fromView:nil];
    
        NSValue *endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
        CGRect keyboardEndFrame = [self.view convertRect:endFrameValue.CGRectValue fromView:nil];
    
        //
        // Get keyboard animation.
    
        NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
        NSTimeInterval animationDuration = durationValue.doubleValue;
    
        NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
        UIViewAnimationCurve animationCurve = curveValue.intValue;
    
        //
        // Create animation.
    
        CGRect tableViewFrame = self.tableView.frame;
        bTableViewFrame.size.height = (keyboardBeginFrame.origin.y - tableViewFrame.origin.y);
        self.tableView.frame = tableViewFrame;
    
        void (^animations)() = ^() {
            CGRect tableViewFrame = self.tableView.frame;
            tableViewFrame.size.height = (keyboardEndFrame.origin.y - tableViewFrame.origin.y);
            self.tableView.frame = tableViewFrame;
        };
    
        //
        // Begin animation.
    
        [UIView animateWithDuration:animationDuration
                              delay:0.0
                            options:(animationCurve << 16)
                         animations:animations
                         completion:nil];
    }
    

提交回复
热议问题