Evgeny Mahnach
Evgeny Mahnach

Reputation: 11

Swift 360 image: How i can add a button in a panoramic image

I have an image, I convert it into a 360 panoramic image, using metal (https://github.com/ejeinc/MetalScope). How can I add a button on the door (see the screenshot) so that by clicking on it, it would go to the next controller with a different panoramic image (another room)

github project : https://github.com/Mahnach/MetalRender

Upvotes: 0

Views: 2089

Answers (1)

Neil Faulkner
Neil Faulkner

Reputation: 526

You can add a tap gesture recogniser to the image, then get the point where image is tapped. If it is tapped near the door, perform segue to the next controller. If you're not sure where the door area is, you can print out the touch point & see where on the image you're tapping.

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)
    }
}

Upvotes: -1

Related Questions