mercredi 6 mai 2015

Save and segue UIImageView after moving with UIPanGestureRecognizer. Swift

Good day. This is my last option — to ask here. The problem is: I am building multiply view app. On the first screen I have UIImageView that I can move with UIPanGestureRecognizer function:

@IBAction func movement(recognizer: UIPanGestureRecognizer) {

    let translation = recognizer.translationInView(self.view)

    if let view = recognizer.view {

        view.center = CGPoint(x:view.center.x + translation.x, y:view.center.y + translation.y)

    }


    recognizer.setTranslation(CGPointZero, inView: self.view)

}

It's a usual code to move things around, I took at raywenderlich.com

So what I want is to save position of the UIImageView element after interaction with it and after segue.

I believe that I need to return CGPoint from this function and segue it like so:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showPlaylistDetail" {
            let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController

playlistDetailController.image2.center = image1.center

        }
    }

So my question(s) is(are):

  1. Do I use right code to move an object with Pan Gesture Recognizer?

  2. How would you return CGPoint from this function and how would you read it?

  3. How would I save UIImageView's position in process of segue and after?

huh... This little bug is killing me. I bet, it is easy to solve, but as far as I am beginner I have no idea how :(

Aucun commentaire:

Enregistrer un commentaire