1 - (IBAction)pause:(id)sender { 2 3 //1. 将当前系统时间,转换为图层的时间 4 NSTimeInterval paseTime = [self.redView.layer convertTime:CACurrentMediaTime() fromLayer:nil]; 5 6 //2.暂停动画 7 self.redView.layer.speed = 0; 8 9 //3. 使图层的状态保持在暂停的瞬间的状态 10 self.redView.layer.timeOffset = paseTime; 11 } 12 - (IBAction)start:(id)sender { 13 14 //1. 获取暂停的时间点 15 NSTimeInterval pauseTime = self.redView.layer.timeOffset; 16 17 //2. 继续动画 18 self.redView.layer.speed = 1; 19 self.redView.layer.timeOffset = 0; 20 self.redView.layer.beginTime = 0; 21 22 //3. 暂停的时间 = 当前时间 - 上一个暂停时间点timeOffset 23 NSTimeInterval beginTime = [self.redView.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pauseTime; 24 self.redView.layer.beginTime = beginTime; 25 }