Swift 360图像:如何在全景图像中添加按钮

时间:2017-11-08 16:03:47

标签: ios swift scenekit metal 360-panorama

我有一张图片,我使用金属(https://github.com/ejeinc/MetalScope)将其转换为360度全景图像。如何在门(see the screenshot)上添加一个按钮,以便通过点击它来进入下一个具有不同全景图像的控制器(另一个房间)

github项目:https://github.com/Mahnach/MetalRender

1 个答案:

答案 0 :(得分:-1)

您可以为图像添加点按手势识别器,然后获取点按图像的位置。如果在门附近轻敲,请执行segue到下一个控制器。如果您不确定门区域的位置,可以打印出触点和放大器。看你正在点击的图像上的哪个位置。

override func viewDidLoad() {
    super.viewDidLoad()

    //Create Tap Gesture
    let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapAction(_:)))

    //Enable image user interaction
    self.imageView.isUserInteractionEnabled = true

    //Add Tap gesture to the image
    self.imageView.addGestureRecognizer(tapGestureRecognizer)
}

@objc func tapAction(_ sender: UITapGestureRecognizer){

    //Get the touch point
    let touchPoint = sender.location(in: self.imageView)

    //Set the door area
    let doorArea = CGRect(x: 200.0, y: 100.0, width: 75.0, height: 100.0)

    //Then check if touch point is near door
    if doorArea.contains(touchPoint){
        //Peform segue
        performSegue(withIdentifier: "nextScene", sender: nil)
    }
}