iOS 7 - Keyboard animation

后端 未结 8 1615
广开言路
广开言路 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:25

    Register for the notification:

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

    Respond by animating a change to the frame.origin.y of the view.

    - (void)keyboardWillShow:(NSNotification *)aNotification {
    
        NSDictionary *userInfo = aNotification.userInfo;
        NSValue *endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
        CGRect keyboardEndFrame = [self.view convertRect:endFrameValue.CGRectValue fromView:nil];
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:[aNotification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
        [UIView setAnimationCurve:[aNotification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]];
        [UIView setAnimationBeginsFromCurrentState:YES];
    
        CGRect searchButtonFrame = self.searchButton.frame;
        searchButtonFrame.origin.y = (keyboardEndFrame.origin.y - searchButtonFrame.size.height);
        self.searchButton.frame = searchButtonFrame;
    
        [UIView commitAnimations];
    }
    

提交回复
热议问题