一、理論基礎(chǔ)

請(qǐng)參考 CGAffineTransform簡(jiǎn)單分析

Demo下載地址:私信回復(fù)“06”

二、效果演示



三、實(shí)現(xiàn)代碼

3.1:位移變換

-(void)positionAnimation{ _DemoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ _demoView.transform = CGAffineTransformMakeTranslation(100, 100); }]; }

3.2:縮放變換

-(void)scaleAnimation{ _demoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ _demoView.transform = CGAffineTransformMakeScale(2, 2); }]; }

3.3:旋轉(zhuǎn)變換

-(void)rotateAnimation{ _demoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ _demoView.transform = CGAffineTransformMakeRotation(M_PI); }]; }

3.4:組合變換

-(void)combinationAnimation{ //仿射變換的組合使用 _demoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ CGAffineTransform transform1 = CGAffineTransformMakeRotation(M_PI); CGAffineTransform transform2 = CGAffineTransformScale(transform1, 0.5, 0.5); _demoView.transform = CGAffineTransformTranslate(transform2, 100, 100); }]; }

3.5:矩陣的反轉(zhuǎn)

-(void)invertAnimation{ _demoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ //矩陣反轉(zhuǎn) _demoView.transform = CGAffineTransformInvert(CGAffineTransformMakeScale(2, 2)); }]; }

四、補(bǔ)充

  • CGAffineTransformIdentity : 單位矩陣變換,一般用于仿射變換的初始化或者還原。
  • CGAffineTransformEqualToTransform(CGAffineTransform t1,
  • CGAffineTransform t2) : 判斷兩個(gè)變換矩陣是否相等
  • CGAffineTransformConcat(CGAffineTransform t1,
  • CGAffineTransform t2) : 得到兩個(gè)矩陣相加后得到的最終矩陣
  • CGPoint CGPointApplyAffineTransform(CGPoint point,
  • CGAffineTransform t) : 某點(diǎn)通過(guò)矩陣變換之后的點(diǎn)
  • CGSize CGSizeApplyAffineTransform(CGSize size, CGAffineTransform t) : 某個(gè)size通過(guò)矩陣變換之后的size
  • CGRect CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t) : 某個(gè)Rect通過(guò)矩陣變換之后的區(qū)域

五、Demo下載地址

Demo下載地址:私信回復(fù)“06”

如果覺(jué)得對(duì)你還有些用,就關(guān)注小編+轉(zhuǎn)發(fā)這一篇文章。你的支持是我繼續(xù)的動(dòng)力。

下篇文章預(yù)告:UICollectionView初步入門(mén)

文章來(lái)源于網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系小編刪除。

1.《ios如何修改cgrect》援引自互聯(lián)網(wǎng),旨在傳遞更多網(wǎng)絡(luò)信息知識(shí),僅代表作者本人觀點(diǎn),與本網(wǎng)站無(wú)關(guān),侵刪請(qǐng)聯(lián)系頁(yè)腳下方聯(lián)系方式。

2.《ios如何修改cgrect》僅供讀者參考,本網(wǎng)站未對(duì)該內(nèi)容進(jìn)行證實(shí),對(duì)其原創(chuàng)性、真實(shí)性、完整性、及時(shí)性不作任何保證。

3.文章轉(zhuǎn)載時(shí)請(qǐng)保留本站內(nèi)容來(lái)源地址,http://f99ss.com/keji/3225546.html