iOS之路11-核心動畫

核心動畫忘得差很少了,特意翻出代碼,從新寫了一遍,如下是核心動畫的步驟動畫

@interface ViewController ()
@property (nonatomic,weak)CALayer *layer;
@end


- (void)viewDidLoad {
    [super viewDidLoad];
    // 核心動畫的步驟
    // 建立圖層
    CALayer *layer = [CALayer layer];
    // 賦值屬性
    self.layer = layer;
    // 圖層的背景顏色
    layer.backgroundColor = [UIColor redColor].CGColor;
    // frame
    layer.frame = CGRectMake(100, 100, 100, 100);
    // 添加到layer
    [self.view.layer addSublayer:layer];
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    CABasicAnimation *anim = [CABasicAnimation animation];
    // 更改layer的哪一個屬性進行核心動畫,scale表明縮放,rotation表明旋轉
    anim.keyPath = @"transform.scale";
    // 改變什麼樣的值
    anim.toValue = @0.5;;;
    // 設置動畫的執行次數,MAXFLOAT最大的執行次數,默認爲0
    anim.repeatCount = 1;
    // 把核心動畫添加到圖層
    [self.layer addAnimation:anim forKey:nil];
}
相關文章
相關標籤/搜索