標籤:
圖層與動畫知識點總結
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編程
一般是三個步驟:
- (2)把Context中的內容送入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篇&知識點總結