gpt4 book ai didi

iphone - UIImageView 旋转动画带易出

转载 作者:行者123 更新时间:2023-11-28 22:53:42 27 4
gpt4 key购买 nike

我现在正在一圈一圈地旋转一个圆形箭头。这很酷,但我想要像其他 View 一样结束时有一些更精致的东西,你可以为它们制作动画以缓解进或出,我想知道你是否可以为此做同样的事情..这是我的代码..

- (IBAction)animator:(id)sender
{
[arrowRotation removeFromSuperview];

//arrow animation
arrowRotation = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
arrowRotation.frame = CGRectMake(148.0, 20.0, 30.0, 30.0);
[self.view addSubview:arrowRotation];



CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 0.75f;
fullRotation.repeatCount = 3;

[arrowRotation.layer addAnimation:fullRotation forKey:@"360"];
}

所以我的问题是,当涉及到第 3 次旋转时,我能否让这个动画放慢速度……就像从 UIView 中缓和一样。如果这是有道理的..

如有任何帮助,我们将不胜感激。

最佳答案

首先,在这一行 fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)]; 中,你的 float ((360*M_PI)/180) 会将圆旋转 360 度,但您的数字有点过大。我的意思是您可以将其简化为 2*M_PI

第二:如果你想自定义更多,你可以使用CAKeyframeAnimation:

CAKeyframeAnimation *rotationAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];

NSArray *rotationValues = [NSArray arrayWithObjects: [NSNumber numberWithFloat: 0], [NSNumber numberWithFloat: (2*M_PI)], nil];

[rotationAnimation setValues:rotationValues];

NSArray *rotationTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],[NSNumber numberWithFloat:1.0f], nil];
[rotationAnimation setKeyTimes:rotationTimes];

NSArray *rotationTimingFunctions = [NSArray arrayWithObjects:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil];
[rotationAnimation setTimingFunctions:rotationTimingFunctions];

rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.duration = 1;

[self.view.layer addAnimation:rotationAnimation forKey:@"animation"];

希望这对您有所帮助!

关于iphone - UIImageView 旋转动画带易出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11255094/

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