帧间的手势驱动动画

Gesture-driven animation between frames

我正在尝试在缩略图框架和全屏框架之间创建交互式动画。向上平移可能会导致框架在两个维度上增长(直到达到全屏),而向下平移则相反。与 Youtube 为视频播放器制作动画的方式非常相似。

我尝试使用 UIPanGestureRecognizer 和当识别器状态为 UIGestureRecognizerStateEnded 时激活的 POPSpringAnimation,如下所示:

- (void)didPan:(UIPanGestureRecognizer *)recognizer
{
    CGPoint point = [recognizer translationInView:self.view.superview];
    self.view.center = CGPointMake(self.view.center.x, self.view.center.y + point.y);
    [recognizer setTranslation:CGPointZero inView:self.view.superview];
    if (recognizer.state == UIGestureRecognizerStateEnded)
    {
        CGPoint velocity = [recognizer velocityInView:self.view.superview];
        // Initaite POPSpringAnimation using velocity and target frame
        // either fullscreen or thumbnail
    }
}

这样做的效果是视图的中心在平移时得到更新,但它的大小只有在您停止平移后才会开始变化。我不想在 didPan: 中手动调整框架大小,而不知道要按什么比例进行调整。

如何创建仅从 A 帧移动到 B 帧的平移驱动动画?

This framework does almost the same thing, but the animation is not interactive. Same thing goes for this 回答。

我建议使用 UIViewPropertyAnimator,在 iOS 10 中添加 class。它可以让您轻松地暂停、反转或来回移动动画。

我有一个关于 GitHub 的演示项目(写在 Swift 中,您可能更难理解,因为您使用的是 Objective-C:

https://github.com/DuncanMC/UIViewPropertyAnimator-test

class 实际上非常容易使用。你应该能够从文档中弄清楚,即使你不能逐行遵循代码,示例项目至少可以作为 API 的路线图使用