gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:35:03 24 4
gpt4 key购买 nike

我正在探索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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com