简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM