- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我似乎无法从我的 CAShapeLayer 的 strokeEnd
属性中删除动画。
文档说该属性是可动画
,但默认情况下不是动画,我无法查明问题所在。有什么建议在哪里看?
这是我的代码:
class ViewController: UIViewController {
let circle = CAShapeLayer()
override func viewDidLoad() {
super.viewDidLoad()
// Circle
circle.fillColor = UIColor.clearColor().CGColor
circle.strokeColor = UIColor.blackColor().CGColor
circle.lineWidth = 10
circle.strokeEnd = 0
circle.lineJoin = kCALineJoinRound
circle.path = UIBezierPath(ovalInRect: CGRectMake(60, 140, 200, 200)).CGPath
circle.actions = ["strokeEnd" : NSNull()]
// Show Button
let showButton = UIButton(frame: CGRectMake(40, 40, 240, 40))
showButton.addTarget(self, action: "showButton", forControlEvents: UIControlEvents.TouchUpInside)
showButton.setTitle("Show circle", forState: UIControlState.Normal)
showButton.backgroundColor = UIColor.greenColor()
// Add to view
self.view.layer.insertSublayer(circle, atIndex: 1)
self.view.addSubview(showButton)
}
func showButton() {
circle.strokeEnd = 1
}
}
最佳答案
您描述的将图层的 strokeEnd 操作设置为 NSNull 的方法可行,但它有点像大锤。当您这样做时,您将永远终止图层的 strokeEnd 属性的隐式动画。
如果这就是您想要的,那没关系。但是,我倾向于使用 David Rönnqvist 在您链接的答案中列出的第二种方法:Making your layer change inside a CATransaction begin/commit block。这是 David 的回答中的代码(非常好,他的帖子一如既往)。
[CATransaction begin];
[CATransaction setDisableActions:YES];
// change your property here
yourShapeLayer.strokeEnd = 0.7;
[CATransaction commit]; // animations are disabled until here...
该代码在 Objective-C 中。将它翻译成 Swift 也不错:
CATransaction.begin()
CATransaction.setDisableActions(true)
yourShapeLayer.strokeEnd = 0.7
CATransaction.commit()
关于ios - 我可以在没有动画的情况下更改 strokeEnd 属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30150298/
我正在尝试为音乐播放器构建进度 View 。总的来说,我对编程完全陌生,现在真的走进了死胡同。 我的进展顺利。我用媒体文件的值(值/持续时间)来制作“中风结束”动画,但中风结束只能到达圆的部分。不过,
这个问题在这里已经有了答案: addArc(withCenter) closing path (2 个答案) 关闭 3 年前。 我正在使用 CAShapeLayer 绘制一个圆圈,由于某种原因,笔画
我有一个 CAShapeLayer以正方形的形式,我设置了 width为 2.0f。 我想为其 strokeEnd 制作动画为此,我使用了 CABasicAnimation像这样: CABasicAn
我正在尝试制作一个类似于 Android Material 设计循环不确定事件指示器的自定义事件指示器。基本上我想画圆圈两次并删除它,但删除和绘制不会同时或速度发生。这是我目前所拥有的: let pr
我似乎无法从我的 CAShapeLayer 的 strokeEnd 属性中删除动画。 文档说该属性是可动画,但默认情况下不是动画,我无法查明问题所在。有什么建议在哪里看? 这是我的代码: class
这是我用来为我的 CAShapeLayer 设置动画的代码: _progressBarLayer.strokeEnd = CGFloat(_progressToDrawForProgress(prog
我有两层。 A 层 和B 层。 我正在将 A 层 的 strokeEnd 从某个值设置为某个新值的动画。我还需要同时更改 Layer B 上的某些内容,但这取决于 Layer A 在设置动画时 str
我有这段代码: let arcPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, frame.width, frame.height))
我正在尝试实现与所附图片类似的效果,其中圆圈根据您的关卡进度进行动画处理,然后在动画路径的两端附加一个标签以显示获得的经验以及未绘制的部分圆圈以显示剩余的经验。我根据需要设置了圆圈动画,但无法想出使标
我的问题是关于跟踪 CAShapeLayer 的 strokeEnd 点坐标的可能性。 我有一个 UISlider,它生成一个介于 0 和 1 之间的变量。我从 CGMutablePathRef 创建
我试图描绘出我放置到 CAShapeLayer 中的路径的形状。在此函数中,points 数组中的点表示正多边形的顶点。但是,动画没有发生。它刚刚出现,完全生动。 代码如下: private func
我是一名优秀的程序员,十分优秀!