反转UIViewPropertyAnimator会导致帧动画问题

Dan*_*son 6 animation objective-c uikit ios uiviewpropertyanimator

我用a UIViewPropertyAnimator来动画画面UICollectionViewCell.我查看平移手势识别器的速度,以决定动画师是自然完成还是反转并返回初始状态.

在所有模拟器中,在我的iPhone 5s以及6s +上,这些动画运行完美无瑕.然而,在我的iPhone 7+上,每当我反转动画时,我都会出现奇怪的帧闪烁.请参阅下面的代码,了解我的工作方式.对iPhone 7+的影响是,一旦我设置reversed = YES然后调用continueAnimationWithTimingParameters:durationFactor:,帧立即跳转到屏幕的完全不同的部分,然后从那里运行反向动画.只有在动画完成运行后,帧才会跳回到它应该恢复的位置.

我试图删除使用弹簧计时参数,但这没有什么区别.

这是代码的抽象版本:

- (void)prepareAnimation {
    // Called when user begins panning in certain direction
    // ...
    self.cardFrameAnimator = [[UIViewPropertyAnimator alloc] initWithDuration:0.5 dampingRatio:0.8 animations:^{
        [self currentCell].frame = targetFrame;
    }];
}

- (void)panningEndedWithTranslation:(CGPoint)translation velocity:(CGPoint)velocity
{
    if (self.cardFrameAnimator.isRunning)
    {
        return;
    }

    CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
    CGVector velocityVector = CGVectorMake(velocity.x / 500, velocity.y / 500);

    __weak CardStackCollectionViewController *weakSelf = self;

    switch (self.currentState) {
        case CurrentStateStacked:
            if (translation.y <= -screenHeight / 3 || velocity.y <= -100)
            {
                // Let the animation run to completion
                self.cardFrameAnimator.reversed = NO;
                [self setCurrentCellsCornerRadius:0];
                [self.cardFrameAnimator addCompletion:^(UIViewAnimatingPosition finalPosition) {
                    weakSelf.activeCellState = CurrentStateFullscreen;
                }];
            }
            else
            {
                // Revert the animation back to the default state
                self.cardFrameAnimator.reversed = YES;
                [self setCurrentCellsCornerRadius:20];
                [self.cardFrameAnimator addCompletion:^(UIViewAnimatingPosition finalPosition) {
                    weakSelf.activeCellState = CurrentStateStacked;
                }];
            }
            break;
        case CurrentStateFullscreen:
            if (translation.y >= screenHeight / 3 || velocity.y >= 100)
            {
                // Let the animation run to completion
                self.cardFrameAnimator.reversed = NO;
                [self setCurrentCellsCornerRadius:20];
                [self.cardFrameAnimator addCompletion:^(UIViewAnimatingPosition finalPosition) {
                    weakSelf.activeCellState = CurrentStateStacked;
                }];
            }
            else
            {
                // Revert the animation back to the default state
                self.cardFrameAnimator.reversed = YES;
                [self setCurrentCellsCornerRadius:0];
                [self.cardFrameAnimator addCompletion:^(UIViewAnimatingPosition finalPosition) {
                    weakSelf.activeCellState = CurrentCellStateFullscreen;
                }];
            }
            break;
    }

    UISpringTimingParameters *springParameters = [[UISpringTimingParameters alloc] initWithDampingRatio:0.8 initialVelocity:velocityVector];
    [self.cardFrameAnimator continueAnimationWithTimingParameters:springParameters durationFactor:1.0];
}
Run Code Online (Sandbox Code Playgroud)