如何将CGPoint从Landscape旋转到Portrait UIImage方向?

时间:2017-05-02 19:58:59

标签: swift3 uibezierpath cashapelayer cgpoint

我有一个UIImageView,我画了一个三角形。积分" A" leftPost& " B" rightPost始终是静态的,彼此之间的距离相同。 "提示"或指向" C"通过点击UIImageView来确定。当图像处于纵向模式时,我可以重新创建UIImageView以及被点击的CGPoint的坐标。

但是,我需要以横向模式显示UIImage并表示相同的三角形。我如何"旋转"我的坐标实现了这个?我也暗示我不是从纵向和横向旋转屏幕。该应用程序始终处于风景中。

import UIKit

class ViewController: UIViewController {

    let bezierPath = UIBezierPath()
    let shapeLayer = CAShapeLayer()
    @IBOutlet weak var imageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let shotGesture = UITapGestureRecognizer(target: self, action: #selector(shotOnNet))

        imageView.addGestureRecognizer(shotGesture)

        //Enable tapping on screen
        imageView.isUserInteractionEnabled = true

    }

    func setupBezierPath(tip: CGPoint) {

        let leftPost = CGPoint(x: 20, y: 50)
        let rightPost = CGPoint(x: 100, y: 50)

        bezierPath.move(to: leftPost)
        bezierPath.addLine(to: rightPost)
        bezierPath.addLine(to: tip)
        bezierPath.close()

    }

    func setupShapeLayer() {
        shapeLayer.path = bezierPath.cgPath
        shapeLayer.fillColor = UIColor.red.cgColor
        shapeLayer.lineWidth = 1.0
     shapeLayer.strokeColor = UIColor.black.cgColor
    }

    func shotOnNet(_ sender: Any) {

        let shot = (sender as! UITapGestureRecognizer).location(ofTouch: 0, in: imageView)

        setupBezierPath(tip: shot)
        setupShapeLayer()
        imageView.layer.addSublayer(shapeLayer)

    }
}

enter image description here

0 个答案:

没有答案