相关疑难解决方法(0)

在Swift 4中用一根手指旋转

我创建了一个UIGestureRecognizer以仅用一根手指即可旋转视图。

视图从一开始就旋转,但是一旦达到一定程度,旋转就会沿另一个方向旋转。

您能帮我提供我的代码吗?

UIViewcontroller <-一切都很好

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    let wheel = TestWheelView()
    wheel.frame = CGRect.init(x: self.view.center.x - 120, y: self.view.center.y - 120, width: 240, height: 240)
    self.view.addSubview(wheel)
    wheel.addGestureRecognizer(TestRotateGestureRecognizer())
}
Run Code Online (Sandbox Code Playgroud)

UIGestureRecognizer <-问题在这里

import UIKit

class TestRotateGestureRecognizer: UIGestureRecognizer {
    var previousPoint = CGPoint()
    var currentPoint = CGPoint()
    var startAngle = CGFloat()
    var currentAngle = CGFloat()
    var currentRotation = CGFloat()
    var totalRotation = CGFloat()

    func angleForPoint(_ point:CGPoint) -> CGFloat{
        var angle = …
Run Code Online (Sandbox Code Playgroud)

rotation uigesturerecognizer ios swift

2
推荐指数
1
解决办法
1202
查看次数

Swift 3:将动画的圆弧颜色填充添加到UIBezierPath

我希望为饼图的一部分的颜色填充设置动画。我通过UIBezierPath()为每个饼图创建一个饼图来创建饼图,然后使用该addArc方法指定圆弧的大小/约束。要设置饼图段的动画,我希望弧的颜色填充从圆的中心到半径末端进行动画处理。但是,我遇到了麻烦。我听说strokeEnd keyPath0到的动画1应该可以工作,但是弧上没有发生动画(弧仅在应用程序启动时出现)。

let rad = 2 * Double.pi
let pieCenter: CGPoint = CGPoint(x: frame.width / 2, y: frame.height / 2)
var start: Double = 0
for i in 0...data.count - 1 {
    let size: Double = Double(data[i])! / 100 // the percentege of the circle that the given arc will take
    let end: Double = start + (size * rad)

    let path = UIBezierPath()
    path.move(to: pieCenter)
    path.addArc(withCenter: pieCenter, radius: frame.width …
Run Code Online (Sandbox Code Playgroud)

animation core-graphics cashapelayer ios swift

1
推荐指数
1
解决办法
2006
查看次数