UIImageView转换丢失滑动手势

时间:2019-02-02 17:12:33

标签: swift uiimageview cgaffinetransform uiswipegesturerecognizer

我有一张想要在用户每次在其上滑动时旋转的图像。它是第一次的,并且只有第一次!视图丢失滑动手势识别器的感觉如何?

        myCircle = UIImageView( ... )
        myCircle.isUserInteractionEnabled = true

        let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(swiping(sender:)))
        swipeLeft.direction = .left
        myCircle.addGestureRecognizer(swipeLeft)
        let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(swiping(sender:)))
        swipeRight.direction = .right
        myCircle.addGestureRecognizer(swipeRight)
    }

    @objc func swiping(sender: UISwipeGestureRecognizer) {
        // this function only called the first time!
        if sender.direction == UISwipeGestureRecognizer.Direction.left {
            myCircleRotation -= CGFloat(Double.pi/2)
        } else if sender.direction == UISwipeGestureRecognizer.Direction.right {
            myCircleRotation += CGFloat(Double.pi/2)
        }
        // if I comment out this next line, function is called (correctly) every swipe!
        myCircle.transform = CGAffineTransform(rotationAngle: myCircleRotation)
    }

1 个答案:

答案 0 :(得分:1)

您可以将Present O/P -('t0', 't1', 't2', 't3', 't5', 't6', 't9', 't10') Expected O/P - ('t0', 't1'),('t2', 't3'),('t5', 't6'),('t9', 't10') 作为容器视图添加到层​​次结构,然后将UIView s添加到容器视图而不是UIGestureRecognizer。这将使你的图像,而不影响手势旋转。

UIImageView