基本概念
struct CGAffineTransform{ CGFloat a, b, c, d; CGFloat tx, ty;};
以上參數(shù)在矩陣中的表示為:
|a b 0| |c d 0| |tx ty 1|
為了把二維圖形的變化統(tǒng)一在一個坐標(biāo)系里,引入了齊次坐標(biāo)的概念坊饶,即把一個圖形用一個三維矩陣表示泄伪,其中第三列總是(0,0,1),用來作為坐標(biāo)系的標(biāo)準(zhǔn)匿级。所以所有的變化都由前兩列完成蟋滴。
基本使用(配合動畫)
旋轉(zhuǎn)[UIView animateWithDuration:0.5 delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{ [UIView setAnimationRepeatCount:1e100];//設(shè)置動畫重復(fù)次數(shù) box.transform = CGAffineTransformMakeRotation(M_PI/2);}completion:NULL];
縮放
[UIView animateWithDuration:0.5 delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{ box.transform = CGAffineTransformMakeScale(0.1, 1);}completion:NULL];
移動
[UIView animateWithDuration:0.5 delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{ box.transform = CGAffineTransformMakeTranslation(50, 50);}completion:NULL];
串聯(lián)
[UIView animateWithDuration:0.5 delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{ CGAffineTransform transform2 = CGAffineTransformMakeTranslation(50, 50); CGAffineTransform transform1 = CGAffineTransformMakeScale(0.1, 1); box.transform = CGAffineTransformConcat(transform1, transform2);}completion:NULL];