Behackful
Behackful

Reputation: 21

Adding button to scrollable panoramic image - IOS Swift 4

I'm designing an iOS app that will let a user pick objects from a panoramic image view. The user will be able to "look around" (left and right) and will need to pick an item from one side.

Now the question is how can I track exactly where the user clicked in the image? The user can move left and right, pinch in and out.

Using Apple ARKit is not an option, this app will be developed later for Android too.

Upvotes: 1

Views: 201

Answers (1)

Behackful
Behackful

Reputation: 21

So I gave it some more thought and a different approach. The answer is to get the coordinates of the image using the code below: It doesn't matter where the focus on while the user interacts with it, you will get the coordinates of the location in the image. Hope this helps someone!

    @IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapAction))
        self.imageView.isUserInteractionEnabled = true
        self.imageView.addGestureRecognizer(tapGestureRecognizer)
    }

@objc func tapAction(sender: UITapGestureRecognizer) {
        let touchPoint = sender.location(in: self.imageView) // Change to whatever view you want the point for
        print(touchPoint)
    }

Upvotes: 1

Related Questions