19

iOS7 のアニメーションは、iOS6 と同じように動作しません。異なるベジエ曲線を使用しているようです。iOS6 は一種の「easeInOutSine」曲線を使用しますが、iOS7 はより「easeInOutExpo」のようなものです。( http://matthewlein.com/ceaser/ )

その曲線を利用する方法はありますか?キーボードの開閉時にアニメーションを同期したい。

4

2 に答える 2

39

これが私のやり方です(少なくともキーボードが表示されようとしているとき)

- (void)keyboardWillShow:(NSNotification *)notification {
    NSDictionary *keyboardAnimationDetail = [notification userInfo];
    UIViewAnimationCurve animationCurve = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue];
    CGFloat duration = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] floatValue];

    [UIView animateWithDuration:duration delay:0.0 options:(animationCurve << 16) animations:^{
        // Set the new properties to be animated here
    } completion:nil];
}

通常どおり、キーボード通知からアニメーション カーブを取得し、ビットシフトしてアニメーション オプションに変換します。

于 2013-09-18T13:40:18.443 に答える
3

更新、7.1 で修正済み。もう必要ありません。


なんらかの理由で、キーボードの終了時にレポートされるアニメーション カーブは正しくありません。実際には 7 << 17 ではなく 6 << 16 のようです。

UIKeyboardWillChangeFrameNotification使用するアニメーション カーブを決定するために、次のことを行います。

NSDictionary *keyboardAnimationDetail = [notification userInfo];

CGRect keyboardEndFrameWindow = [keyboardAnimationDetail[UIKeyboardFrameEndUserInfoKey] CGRectValue];

double keyboardTransitionDuration  = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

// gives incorrect value of 7 on dismissal
// UIViewAnimationCurve keyboardTransitionAnimationCurve  = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue];

CGRect keyboardEndFrameView = [self.view convertRect:keyboardEndFrameWindow fromView:nil];

CGFloat newConstant = (self.view.frame.size.height - keyboardEndFrameView.origin.y);

[UIView animateWithDuration:keyboardTransitionDuration
                      delay:0.0f
                    options:newConstant == 0 ? (6 << 16) : (7 << 16)
                 animations:^{
                     self.tableView.contentInset = UIEdgeInsetsMake(self.tableView.contentInset.top, 0, self.view.frame.size.height - keyboardEndFrameView.origin.y + self.commentToolbar.frame.size.height, 0);
                     self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.tableView.scrollIndicatorInsets.top, 0, self.view.frame.size.height - keyboardEndFrameView.origin.y + self.commentToolbar.frame.size.height, 0);
                     self.commentViewToSuperviewBottomConstraint.constant = (self.view.frame.size.height - keyboardEndFrameView.origin.y);
                     [self.view layoutIfNeeded];
                 }
                 completion:^(__unused BOOL finished){
                 }];

基本的に、新しい y 原点がビューのフレームのすぐ外側にあるかどうかを確認して、キーボード フレームが隠れているかどうかを判断します ( newConstant)。次に、それに基づいて 6 または 7 を使用します。

newConstant == 0 ? (6 << 16) : (7 << 16)

残りは mytableView contentInsetscrollIndicatorInsetsを調整するだけでなく、キーボードで移動するツールバーの定数を変更するだけです。

于 2013-10-17T23:54:01.583 に答える