大家好,又见面了,我是全栈君。
@interface FirstViewController ()
@property (nonatomic,assign)BOOL isplay;
@end
@implementation FirstViewController
@synthesize isplay;
– (void)viewDidLoad
{
[super viewDidLoad];
isplay = NO;
//圆角
self.imgview.layer.cornerRadius = 150.0 / 2.0;
self.imgview.layer.masksToBounds = YES;
//加入动画
CABasicAnimation *monkeyAnimation = [CABasicAnimation animationWithKeyPath:@”transform.rotation.z”];
monkeyAnimation.toValue = [NSNumber numberWithFloat:2.0 *M_PI];
monkeyAnimation.duration = 1.5f;
monkeyAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
monkeyAnimation.cumulative = NO;
monkeyAnimation.removedOnCompletion = NO; //No Remove
monkeyAnimation.repeatCount = FLT_MAX;
[self.imgview.layer addAnimation:monkeyAnimation forKey:@”AnimatedKey”];
[self.imgview stopAnimating];
// 载入动画 但不播放动画
self.imgview.layer.speed = 0.2;
}
– (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//開始动画
– (IBAction)startAnimate:(id)sender {
if (!isplay) {
isplay = YES;
self.imgview.layer.speed = 1.0;
self.imgview.layer.beginTime = 0.0;
CFTimeInterval pausedTime = [self.imgview.layer timeOffset];
CFTimeInterval timeSincePause = [self.imgview.layer convertTime:CACurrentMediaTime() fromLayer:nil] – pausedTime;
self.imgview.layer.beginTime = timeSincePause;
}
}
//停止动画并保存当前的角度
– (IBAction)stioAnimate:(id)sender {
if (isplay) {
isplay = NO;
CFTimeInterval pausedTime = [self.imgview.layer convertTime:CACurrentMediaTime() fromLayer:nil];
self.imgview.layer.speed = 0.0;
self.imgview.layer.timeOffset = pausedTime;
}
}
@end
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/115597.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...