草庐IT

CAshapeLayer

全部标签

ios - Swift 3 中的 CAShapeLayer 点击检测

我有一个CAShapeLayer,我已将其填充颜色标记为透明。当我点击线上时,它并不总是检测CAShapeLayercgpath是否包含点击点。我的代码如下:overridefunctouchesBegan(_touches:Set,withevent:UIEvent?){lettouch=touches.firstguardletpoint=touch?.location(in:self)else{return}forsublayerinself.layer.sublayers!{ifletl=sublayeras?CAShapeLayer{ifletpath=l.path,path

ios - 在不使用 CAShapeLayer 的情况下冲破 UIBezierPath 的笔划并为此笔划设置动画

UIBezierPath只有在UIView的drawRect()方法中使用时才会变成虚线,如下所示:overridefuncdraw(_rect:CGRect){letpath=UIBezierPath()letp0=CGPoint(x:self.bounds.minX,y:self.bounds.midY)path.move(to:p0)letp1=CGPoint(x:self.bounds.maxX,y:self.bounds.midY)path.addLine(to:p1)letdashes:[CGFloat]=[0.0,16.0]path.setLineDash(dashes,

ios - 将图层属性从 UIView 覆盖到子类 UIView

我正在将一些Swift代码转换为ObjectiveC。不太熟悉Swift语法。overridevarlayer:CAShapeLayer{get{returnsuper.layeras!CAShapeLayer}}我不明白如何在Objective-C中覆盖此属性。我试过了在.h文件中@property(nonatomic,readonly,retain)CAShapeLayer*layer;在.m文件中@synthesizelayer;但是好像不行。没有错误,但代码未按预期执行。 最佳答案 你现在需要做的只是实现图层属性的gette

swift - transform.scale 上的 CABasicAnimation 在 X 和 Y 轴上转换 CAShapeLayer

我试图在按钮周围添加脉动效果,但是,我使用的代码翻译了CAShapeLayer并增加了它的大小。如何在此动画期间仅增加CAShapeLayer的比例,同时保持其在View中的位置不变?我已将代码隔离到一个执行此动画的简单项目中,并且它仍在发生。在此处的视频中查看效果:https://imgur.com/a/AbTtLKe测试一下:创建一个新项目在View中心添加一个按钮将其作为名称为beginButton的IBOutlet链接到viewControllers代码文件这是我的代码:letpulsatingLayer=CAShapeLayer()overridefuncviewDidLoa

swift - 如何删除进度条圈中的 CAShapeLayer

我有以下代码,我正在实现以下载带有进度圈的PDF。它对我有用,首先我检查文件是否已保存在“文档”目录中,如果是,我只显示PDF,如果尚未加载pdf文件,则begindDownloadFile()lassViewController:UIViewController,URLSessionDownloadDelegate{@IBOutletweakvarpdfView:PDFView!leturlString="https://d0.awsstatic.com/whitepapers/KMS-Cryptographic-Details.pdf"letshapeLayer=CAShapeLa

ios - 使用 CAShapeLayer 支持的 UIView 塑造一个三角形

从教程:http://swiftiostutorials.com/tutorial-draw-nice-triangle-view-border-cashapelayer/,我设法创建了一个三角形:classTriangle:UIView{overridefuncdrawRect(rect:CGRect){letmask=CAShapeLayer()mask.frame=self.layer.boundsletwidth=self.layer.frame.size.widthletheight=self.layer.frame.size.heightletpath=CGPathCrea

ios - Swift - 使用 Xcode 中的蓝色拖线在两个标签或按钮之间创建连接

我已经成功地像在Xcode中一样创建了蓝线,但是当线的终点被拖动并释放到其他标签或按钮上方以便建立连接时,您如何识别?代码classViewController:UIViewController{@IBOutletvarlabel:UILabel!@IBOutletvarlabel2:UILabel!privatelazyvarlineShape:CAShapeLayer={varcolor=hexStringToUIColor(hex:"#5DBCD2")letlineShape=CAShapeLayer()lineShape.strokeColor=UIColor.blue.cgC

ios - 在 UIView Swift 中居中 CAShapeLayer

我无法在UIView中将CAShapeLayer居中。我搜索过,大多数解决方案来自2015年前的ObjC或尚未解决。附件是图片的样子。当我检查它时,它在红色View内,但我不知道为什么它不居中。我试过调整它的大小,但仍然不起作用。letprogressView:UIView={letview=UIView()view.backgroundColor=.redreturnview}()//MARK:-ViewDidLoadoverridefuncviewDidLoad(){super.viewDidLoad()view.addSubview(progressView)progressVi

ios - CAShapeLayer mask 从底部显示

我正在尝试从图像底部创建“显示”效果。我认为这就像将anchorPoint设置为CGPointMake(0.5,1.0)或将contentsGravity设置为kCAGravityTop一样简单,但这些选项都不起作用。我的当前代码有效,但从上到下进行动画处理。这是揭示的想法:http://giphy.com/gifs/xTiTnBzItdgaD1xHMc我如何使它从下到上进行?这是代码letpath=UIBezierPath(rect:CGRectMake(0,0,imgEmptyBase.width,imgEmptyBase.height-80))letmask=CAShapeLay

swift - CAShapeLayer shadowPath 动画。如何防止动画完成时的阴影填充?

我正在创建一个随机的UIBezierPath,将路径设置为CAShapeLayer的.path属性,然后为设置动画>CAShapeLayer的描边是这样的://Getapathletpath=createBezierPath()//Shapelayerpropertiesletcolor=randomCGColor()//ColorofpathandshadowletlineWidth=CGFloat(arc4random_uniform(50)+11)//WidthoflineandshadowradiusshapeLayer.path=path.CGPathshapeLayer.l