objective-c - iOS触控,手势,动画

标签 objective-c ios animation core-animation

我正在探索iOS4.3 SDK,并想实现特定的动画效果。但是不知道该怎么做。它是这样的-我在屏幕上有一个方框,当用户将手指放在方框上并拖动手指时,方框应该跟随他。到这里很容易。我能够像这样实现它-

-(void)touchesEnded:(NSSet *)touches 
          withEvent:(UIEvent *)event
{
    UITouch *touch   = [touches anyObject];
    CGPoint location = [touch locationInView:self.view];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:2];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    CGAffineTransform scaleTrans  = CGAffineTransformMakeScale(scaleFactor, scaleFactor);
    CGAffineTransform rotateTrans = CGAffineTransformMakeRotation(angle * M_PI / 180);
    boxView.transform = CGAffineTransformConcat(scaleTrans, rotateTrans);
    angle             = (angle == 180 ? 360 : 180);
    scaleFactor       = (scaleFactor == 2 ? 1 : 2);
    boxView.center    = location;
    [UIView commitAnimations];
}

但是当用户抬起手指时,我希望盒子继续运动(好像有动量)。就像苹果使用的橡皮筋滚动效果一样。即使您退出滚动,屏幕也会滚动并缓慢停止。我该如何实施?

最佳答案

您为什么不考虑使用 UIPanGestureRecognizer 呢?您可以使用translationInView:在移动手指的同时移动框。当手势的stateUIGestureRecognizerStateEnded时,您可以使用velocityInView:获得所需的跟进效果。

关于objective-c - iOS触控,手势,动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6225387/

相关文章:

ios - UISegmentedControl 具有两个 UICollectionViews 来显示图像。多线程

ios - 如何在不丢失选项卡的情况下在选项卡式应用程序上加载另一个 View Controller

jquery - div重叠和碰撞位置

android 二维位图绘制

iphone - 如何在不重新加载完整表格的情况下更新 UITableVIewCell

ios - 将 CALayer 设置为 SCNMaterial 的漫反射内容

ios - 在运行时获取主 Storyboard

ios - 未从 WatchApp Target 获取存储的 UIImage

ios - 像表格一样显示具有动态大小的标签,但不重叠

javascript - 点点点点点点作为加载?