1

我正在寻找带有文字的气泡动画,以在屏幕上滑动和滑出。此动画的理想实现是启用分页的 iOS 水平滚动。当我到达语音气泡的末尾时,我绝对想要“反弹”,并且我绝对希望气泡跟踪手指直到它们滑出屏幕之前的某个点。我相信这与滑动不同(这只是一个方向的轻弹)。

然而,水平滚动的问题在于它针对静态数量的图像进行了优化。我将拥有动态数量的图像,据我所知,您不能将图像动态附加到水平滚动条。这个想法是应用程序在您继续浏览滚动条时动态地将内容添加到滚动条中。

卷轴很容易上手,但我现在必须把它拆掉。我如何开始使用手势(我不确定标准手势识别器此时是否对我有用)以及动画?我以前从未使用过这部分 iOS 代码。

4

1 回答 1

3

我不确定我是否完全遵循您的问题,但是如果您想根据手势为某物的运动设置动画,您可以使用 aUIPanGestureRecognizer并更改center您想要的任何子视图。例如,viewDidLoad你会:

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(movePiece:)];
[whateverViewYouWantToAnimate addGestureRecognizer:panGesture];

然后,您可以让手势识别器将其移动到您想要的任何位置:

- (void)movePiece:(UIPanGestureRecognizer *)gestureRecognizer
{
    static CGPoint originalCenter;

    if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
    {
        originalCenter = [gestureRecognizer view].center;
    }
    else if (gestureRecognizer.state == UIGestureRecognizerStateChanged)
    {
        CGPoint translation = [gestureRecognizer translationInView:self.view];

        gestureRecognizer.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y);

        // if you wanted to animate both left/right and up/down, it would be:
        // gestureRecognizer.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y + translation.y);
    }
    else if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
    {
        // replace this offscreen CGPoint with something that makes sense for your app

        CGPoint offscreen = CGPointMake(480, gestureRecognizer.view.center.y);

        [UIView animateWithDuration:0.5
                         animations:^{
                             gestureRecognizer.view.center = offscreen;
                         }
                         completion:^(BOOL finished){
                             // when you're done, you might want to do whatever cleanup
                             // is appropriate for your app (e.g. do you want to remove it?)
                             [gestureRecognizer.view removeFromSuperview];
                         }];
    }
}
于 2012-09-28T21:08:00.060 回答