Thursday, February 21, 2019

Swipe to open new screen Swift

We want user can swipe screen to open new class, use this function.
func tap (g:UIGestureRecognizer) {
let vc = second()
self.presentViewController(vc, animated: true, completion: nil)
 }
Add this line in to viewDidLoad.
let t = UIPanGestureRecognizer(target:self, action:#selector(tap(_:)))
view.addGestureRecognizer(t)
On new class, if want swipe back to previous screen, use this.
func tap (g:UIGestureRecognizer) {
self.dismissViewControllerAnimated(true, completion: nil)
    }
Add to viewDidLoad.
let t2 = UIPanGestureRecognizer(target:self, action:#selector(second.tap(_:)))
view.addGestureRecognizer(t2)
}


No comments:

Post a Comment