日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CAShapeLayer的使用[1]

發(fā)布時間:2025/3/15 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CAShapeLayer的使用[1] 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

CAShapeLayer的使用[1]

?

使用CoreAnimation繪制動畫帶來的系統(tǒng)開銷非常的小,CoreAnimation通常都是使用GPU的.

CAShapeLayer屬于CoreAnimation中很重要的一種layer,無論是作為mask還是作為進度條顯示都非常的好用,我用CAShapeLayer實現(xiàn)了如下復(fù)雜的效果.

// // RootViewController.m // // Copyright (c) 2014年 Y.X. All rights reserved. // #import "RootViewController.h" #import "UIImage+ImageEffects.h"@interface RootViewController ()@property (nonatomic, strong) UIView *showView; @property (nonatomic, strong) CAShapeLayer *oneReferenceLayer; @property (nonatomic, strong) CAShapeLayer *maskLayer;@end#define DEGREES(degrees) ((M_PI * (degrees))/ 180.f)@implementation RootViewController- (void)handlePan:(UIPanGestureRecognizer *)recognizer {// 拖拽CGPoint translation = [recognizer translationInView:self.view];recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,recognizer.view.center.y + translation.y);[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];// 關(guān)閉CoreAnimation實時動畫繪制(核心) [CATransaction setDisableActions:YES];_maskLayer.position = recognizer.view.center; }- (void)viewDidLoad {[super viewDidLoad];/* ====== 背景View ====== */UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];imageView.image = [UIImage imageNamed:@"back"];[self.view addSubview:imageView];/* ====== 作為mask的View ====== */_maskLayer = [CAShapeLayer layer];// 貝塞爾曲線(創(chuàng)建一個圓)UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(0, 0)radius:100startAngle:DEGREES(0)endAngle:DEGREES(360)clockwise:YES];// 獲取path_maskLayer.path = path.CGPath;_maskLayer.position = CGPointMake(_showView.bounds.size.width/2.f,_showView.bounds.size.height/2.f);// 設(shè)置填充顏色為透明_maskLayer.fillColor = [UIColor blackColor].CGColor;_maskLayer.position = self.view.center;UIView *blurView = [[UIView alloc] initWithFrame:self.view.bounds];blurView.backgroundColor = [UIColor blackColor];[self.view addSubview:blurView];blurView.layer.mask = _maskLayer;blurView.layer.contents = (__bridge id)([[UIImage imageNamed:@"back"] blurImage].CGImage);/* ====== 透明的View,用于maskView中的ShapeLayer的參考View(用于拖拽) ====== */_showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];_showView.backgroundColor = [UIColor clearColor];_showView.center = self.view.center;[self.view addSubview:_showView];UIPanGestureRecognizer *recognizer = \[[UIPanGestureRecognizer alloc] initWithTarget:selfaction:@selector(handlePan:)];[_showView addGestureRecognizer:recognizer]; }@end

這個地方很關(guān)鍵哦,沒有關(guān)閉的話會非常的卡頓的.

?

shapeLayer作為mask的一些技巧.

?

?

總結(jié)

以上是生活随笔為你收集整理的CAShapeLayer的使用[1]的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。