0
我用coreAnimation但不能作爲單獨的功能之前,而是這樣的事情:如何使用返回UIBezierPath來啓動動畫的函數?
let v1 = UIView(frame: CGRect(x: 100, y: 100, width: 50, height: 50))
v1.backgroundColor = UIColor.green
view.addSubview(v1)
let animation = CABasicAnimation(keyPath: "cornerRadius")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.fillMode = kCAFillModeForwards
animation.isRemovedOnCompletion = false
animation.fromValue = v1.layer.cornerRadius
animation.toValue = v1.bounds.width/2
animation.duration = 3
v1.layer.add(animation, forKey: "cornerRadius")
現在,我嘗試使用返回UIBezierPath功能,但我不能確定如何正確地使用它
func circlePathWithCenter(center: CGPoint, radius: CGFloat) -> UIBezierPath {
let circlePath = UIBezierPath()
circlePath.addArc(withCenter: center, radius: radius, startAngle: -CGFloat.pi, endAngle: -CGFloat.pi/2, clockwise: true)
circlePath.addArc(withCenter: center, radius: radius, startAngle: -CGFloat.pi/2, endAngle: 0, clockwise: true)
circlePath.addArc(withCenter: center, radius: radius, startAngle: 0, endAngle: CGFloat.pi/2, clockwise: true)
circlePath.addArc(withCenter: center, radius: radius, startAngle: CGFloat.pi/2, endAngle: CGFloat.pi, clockwise: true)
circlePath.close()
return circlePath
}
我試圖創建一個自定義的CALayer但得到警告
結果調用的「circlePathWithCenter(中心:半徑:)」是未使用
這裏是代碼調用函數中的viewController
@IBAction func buttonPressed(_ sender: Any) {
let point = CGPoint(x:self.view.frame.origin.x, y: 100)
//morphLayer is the name of the custom CALayer
let newLayer = morphLayer(frame: CGRect(x: 10, y: 10, width: 100, height: 100))
newLayer.circlePathWithCenter(center: point, radius: 100) // warning here
}
任何幫助將不勝感激!