0
I have a little problem with my code. I have a view with two textFields, one at the top and the other at the bottom, both on a View image. I added a Pangesture function to allow the movement of these textFields after loading an image. Allowing text to be positioned on the image in the location the user chooses. The problem is that after using Pangesture and repositioning the textFields, the user can share the new image through an Activityview, however when activityView appears the textFields go back to the original position, as if the view were rebooted. How do I fix the textfields in the new final positions? What am I doing wrong or not doing? Do I need to touch the constraints? Follow the parts of my code to facilitate understanding...
//MARK: - PAN GESTURE RECOGNIZER
//Permiti a movimentação do textField superior por gesto.
@IBAction func didPanTfTop(_ sender: UIPanGestureRecognizer) {
let translation = sender.translation(in: self.view)
if sender.state == .began {
print("Gesture began")
textFieldOriginalCenter = tfTop.center
} else if sender.state == .changed {
print("Gesture is changed")
tfTop.center = CGPoint(x: textFieldOriginalCenter.x + translation.x, y: textFieldOriginalCenter.y + translation.y)
} else if sender.state == .ended {
print("Gesture ended")
}
}
//Permiti a movimentação do textField inferior por gesto.
@IBAction func didPanTfBottom(_ sender: UIPanGestureRecognizer) {
let translation = sender.translation(in: self.view)
if sender.state == .began {
print("Gesture began")
textFieldOriginalCenter = tfBottom.center
} else if sender.state == .changed {
print("Gesture is changed")
tfBottom.center = CGPoint(x: textFieldOriginalCenter.x + translation.x, y: textFieldOriginalCenter.y + translation.y)
} else if sender.state == .ended {
print("Gesture ended")
}
}
}
Here follows the activityView
//Aciona uma activeView para compartilhar o Meme
@IBAction func share(_ sender: UIBarButtonItem) {
Feedback.share.hapticFeedback()
let memeImage = generateMemedImage()
let activityView = UIActivityViewController(activityItems: [memeImage], applicationActivities: nil)
activityView.completionWithItemsHandler = { (activityType: UIActivity.ActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) -> Void in
if completed {
self.save()
print("Image has saved")
}
}
present(activityView, animated: true, completion: nil)
}