如何使用基于BLOCK的动画旋转UIImageView 360度?
这是我的尝试,但它重复180次旋转而不是连续两次动画
void (^anim) (void) = ^{
uiImgDisc.transform = CGAffineTransformMakeRotation(3.14159265);
};
void (^after) (BOOL) = ^(BOOL f){
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationCurveLinear
animations:^(void){
uiImgDisc.transform = CGAffineTransformMakeRotation(3.14159265);
}
completion:nil];
};
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationCurveLinear | UIViewAnimationOptionRepeat
animations:anim
completion:after];
答案 0 :(得分:0)
它不是基于块的,但您可能想尝试使用CAKeyFrameAnimation,您可以在其中指定动画需要合并的几个关键帧。相对于基于块的方法的好处是核心动画方法将允许更流畅的动画。
可能有点矫枉过正,因为正如Rob所说,你可以做一个CABasicAnimation并将fromValue和toValue分别设置为0和2 * M_PI。但是这个例子向您展示了如何使用流体运动进行任意旋转动画。
首先,确保将QuartzCore Framework添加到构建阶段。然后确保使用
导入标题#import <QuartzCore/QuartzCore.h>
然后在你的旋转方法中,执行以下操作:
CAKeyframeAnimation *theAnimation = [CAKeyframeAnimation animation];
theAnimation.values = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(0, 0,0,1)],
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(3.13, 0,0,1)],
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(6.26, 0,0,1)],
nil];
theAnimation.cumulative = YES;
theAnimation.duration = 1.0;
theAnimation.repeatCount = 0;
theAnimation.removedOnCompletion = YES;
theAnimation.timingFunctions = [NSArray arrayWithObjects:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut],
nil
];
[imageView.layer addAnimation:theAnimation forKey:@"transform"];
受到以下内容的启发:https://github.com/jonasschnelli/UIView-i7Rotate360
祝你好运!
吨