草庐IT

ios - 如何屏蔽和添加阴影到 UIView

我正在制作一个自定义View,我想屏蔽它并为其添加阴影。掩码:letp=UIBezierPath()p.moveToPoint(CGPointMake(20,20))p.addLineToPoint(CGPointMake(100,20))p.addLineToPoint(CGPointMake(100,50))p.addLineToPoint(CGPointMake(110,55))p.addLineToPoint(CGPointMake(100,60))p.addLineToPoint(CGPointMake(100,100))p.addLineToPoint(CGPointMak

swift - 我如何使用 CALayer 创建一个圆圈?

我测试了下面的代码,但是当我给它约束时它变成了一个小圆圈:overridefuncdrawRect(rect:CGRect){varpath=UIBezierPath(ovalInRect:rect)fillColor.setFill()path.fill()//setupthewidthandheightvariables//forthehorizontalstrokeletplusHeight:CGFloat=300.0letplusWidth:CGFloat=450.0//createthepathvarplusPath=UIBezierPath()//setthepath'sl

swift - 我如何使用 CALayer 创建一个圆圈?

我测试了下面的代码,但是当我给它约束时它变成了一个小圆圈:overridefuncdrawRect(rect:CGRect){varpath=UIBezierPath(ovalInRect:rect)fillColor.setFill()path.fill()//setupthewidthandheightvariables//forthehorizontalstrokeletplusHeight:CGFloat=300.0letplusWidth:CGFloat=450.0//createthepathvarplusPath=UIBezierPath()//setthepath'sl

ios - 如何在 CALayer 上进行转换?

在写这个问题之前,我已经有过Affinetransformsforviews的经验阅读Transformsdocumentation在Quartz2D编程指南中看过thisdetailedCALayertutorial下载并运行LayerPlayerproject来自Github但是,我仍然无法理解如何对图层进行基本变换。寻找平移、旋转和缩放的解释和简单示例一直很困难。今天我终于决定坐下来,做一个测试项目,然后弄清楚。我的回答如下。笔记:我只做Swift,但如果其他人想添加Objective-C代码,请成为我的客人。在这一点上,我只关心理解2D变换。 最佳答

ios - 如何在 CALayer 上进行转换?

在写这个问题之前,我已经有过Affinetransformsforviews的经验阅读Transformsdocumentation在Quartz2D编程指南中看过thisdetailedCALayertutorial下载并运行LayerPlayerproject来自Github但是,我仍然无法理解如何对图层进行基本变换。寻找平移、旋转和缩放的解释和简单示例一直很困难。今天我终于决定坐下来,做一个测试项目,然后弄清楚。我的回答如下。笔记:我只做Swift,但如果其他人想添加Objective-C代码,请成为我的客人。在这一点上,我只关心理解2D变换。 最佳答

ios - CALayer 和 UIView 的区别绘制

我有一个组件,其中包含一个UIView子类和一个自定义CAlayer。在UIView中有一个用CoreGraphics绘制的圆,这是代码:CGRectb=self.bounds;intstrokeSize=2;CGRectarcBounds=CGRectMake(b.origin.x+1,b.origin.y+1,b.size.width-2,b.size.height-2);CGContextSaveGState(ctx);{CGContextSetLineWidth(ctx,strokeSize);CGContextSetStrokeColorWithColor(ctx,[UICo

objective-c - 清除 CALayer

我使用CALayer和CATextLayers在iPhone的数独网格上布置数字。我有一个列出了一些数独的tableView。当我点击一个表格单元格时,它会在另一个推送到导航Controller的viewController中显示数独游戏。在我的-(void)viewWillAppear...方法中,我调用了我的-(void)loadSudoku方法,我将在下面向您展示该方法。问题是当您查看一个数独时,使用导航栏中的“后退”按钮返回到TableView,然后点击另一个数独。然后旧的数独还在,新的画在旧的上面。我想我需要以某种方式清除旧的。有任何想法吗?我确实通过实际数独网格的界面生成器

ios - 反转 CALayer 蒙版

我正在尝试使用带有图像的CALayer作为屏蔽UIView的内容。对于面具,我有复杂的png图像。如果我将图像应用为view.layer.mask,我会得到与我想要的相反的行为。有没有办法反转CAlayer?这是我的代码:layerMask=CALayer()guardletlayerMask=layerMaskelse{return}layerMask.contents=#imageLiteral(resourceName:"mask").cgImageview.layer.mask=layerMask//WhatIwouldliketotoisview.layer.mask=lay

ios - CALayer : Screen point to Layer point

我有一个在屏幕坐标中的CGPoint。我还有一个应用了变换矩阵(缩放、旋转和平移)的CALayer。如何将屏幕坐标中的点转换为图层的局部坐标? 最佳答案 CALayer有执行此操作的方法,请在documentation中查找–convertPoint:fromLayer:和–convertPoint:toLayer: 关于ios-CALayer:ScreenpointtoLayerpoint,我们在StackOverflow上找到一个类似的问题: https:

ios - CALayer.draw(in :) and CALayer. needsDisplay(forKey :) not called when expected, presentation layer unexpectedly nil

我正在尝试实现一个具有隐式动画属性的图层,但我看到了一些非常奇怪的行为。这是一个简单的层,它演示了我的意思:classCustomLayer:CALayer{overrideinit(){super.init()implcitlyAnimatedProperty=0.0000needsDisplayOnBoundsChange=true}overrideinit(layer:Any){super.init(layer:layer)implcitlyAnimatedProperty=(layeras!CustomLayer).implcitlyAnimatedProperty}requi