iOS開發——動畫OC篇&知識點總結

來源:互聯網
上載者:User

標籤:

圖層與動畫知識點總結

 

1.Core Animation

 

  非娛樂類的軟體都會用到的動畫,操作簡單。

 

2.Quartz 2D繪圖

 

   是一個2D繪圖引擎。

 

  •   (1) 繪圖Context是一個繪圖的目標對象,定義了繪圖的基本屬性,如顏色、繪圖範圍、線寬及樣式等。

 

  •    (2)通過UIView會建立Context,可以用類似如下的語句來得到當前的Context.

 

   CGContextRef currentContext = UIGraphicsGetCurrentContext();

 

  •    (3)如果在對其進行修改前想要儲存目前狀態,可以使用UIGraphicsPushContext;

 

         要恢複儲存過的Context,則可用UIGraphicsPopContext。

 

  •    (4)path,路徑其實就是用一系列座標點標識出來的一條曲線或折線,建立好之後就可以沿其畫線,或者對封閉的空間進行填充。 

 

3.OpenGL ES編程

 

  一般是三個步驟:

 

  • (1)在Context中繪圖

 

  • (2)把Context中的內容送入framebuffer

 

  • (3)顯示framebuffer 

 

4.Metal(底層API)

蘋果最新推出的Metal架構支援GPU硬體加速、進階3D圖形渲染以及大資料並行運算。且提供了先進而精簡的API來確保架構的細粒度(fine-grain),並且在組織架構、程式處理、圖形呈現、運算指令以及指令相關資料資源的管理上都支援底層控制。其核心目的是儘可能的減少CPU開銷,而將運行時產生的大部分負載交由GPU承擔。   ——Metal編程指南

 

 

 

下面是一些關於開發遇到的技術問題總結

/**************************************************************************************************************/

複製:根據對應的屬性複製一個圖層

 

 1     CAReplicatorLayer *re = [CAReplicatorLayer layer]; 2  3     re.frame = self.drawView.bounds; 4  5      6  7     re.instanceCount = 5; 8  9     re.instanceTransform = CATransform3DMakeTranslation(60, 0, 0);10 11     12 13     re.instanceDelay = 0.5;14 15     16 17 //    re.instanceColor = [UIColor colorWithWhite:1 alpha:0.2].CGColor;18 19     20 21     [self.drawView.layer addSublayer:re];

 

漸層:使一個View中顏色布局漸層分配

    

 1     CAGradientLayer *gra = [CAGradientLayer layer]; 2  3     _gra = gra; 4  5     gra.frame = _imgBottom.bounds; 6  7      8  9     gra.startPoint = CGPointMake(0, 0);10 11     gra.endPoint = CGPointMake(0, 1);12 13     14 15     gra.colors = @[(id)[UIColor whiteColor].CGColor, (id)[UIColor grayColor].CGColor];16 17     18 19     gra.opacity = 0;20 21     22 23     [_imgBottom.layer addSublayer:gra];24 25     

 

    

:截取螢幕地區作為圖片儲存

 

 1 /** 2  3  *  產生 4  5  */ 6  7 - (void)createScreenShot 8  9 {10 11     UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, 0.0);12 13     [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];14 15     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();16 17     [self.images addObject:image];18 19 }20 21  

 

快速合并兩張圖片;

 1     /** 2  3      *  先設定兩張圖片,並且將空間的寬度和圖片的寬度相等,高度等於圖片的一半,使用下面的方法實現兩張圖片的快速合并 4  5      */ 6  7      8  9     //設定內容的範圍10 11     _imgTop.layer.contentsRect = CGRectMake(0, 0, 1, 0.5);12 13     _imgBottom.layer.contentsRect = CGRectMake(0, 0.5, 1, 0.5);14 15     16 17     //設定錨點使得移動18 19     _imgTop.layer.anchorPoint = CGPointMake(0.5, 1);20 21     _imgBottom.layer.anchorPoint = CGPointMake(0.5, 0);22 23  24 25  

 

立體感:遠小近大的效果

 

 1     CATransform3D trans = CATransform3DIdentity; 2  3      4  5     CGFloat d = 100; 6  7      8  9     trans.m34 = -1 / d;10 11     12 13     14 15     trans = CATransform3DMakeRotation(-angle, 1, 0, 0);16 17     18 19     self.imgTop.layer.transform = trans;20 21     

 

iOS開發——動畫OC篇&知識點總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.