創建動畫
CAKeyframeAnimation * keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"bounds"];
修改屬性
keyFrame.duration = 3;
keyFrame.values = @[[NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)], [NSValue valueWithCGRect:CGRectMake(0, 0, 250, 250)] , [NSValue valueWithCGRect:CGRectMake(0, 0, 300, 300)]];
keyTimes : 值代表了出現動畫的時刻 , 值得范圍是[0, 1],
keyTimes 和Value 是一一對應的 數字是百分比 , 數字必須是遞增的 , [0 - 0.4] 執行第一幀 [0.4 - 0.8] 第二幀 [0.8 - 1] 執行第三幀
keyFrame.keyTimes = @[@(0.4),@(0.8),@(1)];
添加動畫
[self.changeView.layer addAnimation:keyFrame forKey:@"keyFrame"];
CAKeyframeAnimation * keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
keyFrame.duration = 100;
keyFrame.values = @[(id)[UIColor greenColor].CGColor , (id)[UIColor blueColor].CGColor , (id)[UIColor purpleColor].CGColor , (id)[UIColor whiteColor].CGColor];
keyTimes中的第一個值是 0 , 不能被修改
keyFrame.keyTimes = @[@(0.1),@(0.4),@(0.6),@(0.7)];
[self.changeView.layer addAnimation:keyFrame forKey:nil];
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。