Reputation: 94
How do I prevent Xcode from preforming a segue back to previous view controller/screen when I tap on a screen.
When I click anywhere on a view controller/screen it sends me back to the previously viewed view controller/screen.
I've tested with the simulator and on a real iPhone and it does the same thing. Additionally, I've tested this by removing all segues in Xcode and it still sends me back to previous screen if I click anywhere.
[UPDATE WITH CODE]
View Controller #1:
import UIKit
class FirstViewController: UIViewController {
// Button
@IBAction func btn(_ sender: Any) {
performSegue(withIdentifier: "SecondView", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
There is then a segue added from View Controller #1 to View Controller #2 - a present modally with an identifier of "SecondView".
View Controller #2:
import UIKit
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
Upvotes: 0
Views: 310
Reputation: 94
I found an answer to my question...
Here is the answer:
private func removePartialCurlTap() {
if let gestures = self.view.gestureRecognizers as? [UIGestureRecognizer] {
for gesture in gestures {
self.view.removeGestureRecognizer(gesture)
}
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
removePartialCurlTap()
}
The issue seems to be the transition used for the Seque, specially when using "Partial Curl" you get this issue. I'm guessing it's a bug in Xcode / iOS, or otherwise not documented well that if you use that specific transition you need to basically remove the GestureRecognizer so the user doesn't get sent back to the previous screen when they simple click someone on the screen.
Credit to Anton Rodzik for posting an answer to this here: How to disable auto segue back to main screen in Xcode?
Upvotes: 2
Reputation: 64
hi first how the animation takes place I mean transition effect ,If it is from top to bottom then dismiss is firing , try view interaction enable is false for debugging purpose and post the result as reply
Upvotes: 0
Reputation: 12723
I do not konw your detail code,just offer one method to do,use EventTouch or UITapGestureRecognizer can do it,in View Controller #2: EventTouch
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
dismiss(animated: Bool)
}
or UITapGestureRecognizer
func handleTap(sender: UITapGestureRecognizer) {
if sender.state == .ended {
// handling code
dismiss(animated: Bool)
}
}
hope can help you.
Upvotes: 0
Reputation: 110
It seems like you have a full screen UIButton
or a UIGestureRecogniser
triggering a dismiss(animated: Bool)
or an unwind segue.
Please share your code.
Upvotes: 0