您好,我正在使用以下代码关闭命令,以使用手势通过滑动操作查看控制器。
在这里,我向屏幕展示按钮操作。
在显示的屏幕中,我要重新加载主视图后关闭了滑动操作。
let sb = UIStoryboard.init(name: "Pickup", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "CleaningnoteController")as! CleaningnoteController
vc.dcnote = self.dryclean
vc.scheduleid = String(scheduleId)
self.navigationController?.present(vc, animated: true, completion: nil)
//IN presented screen.
Here uiview is the added view on the Viewcontroller.
var initialTouchPoint: CGPoint = CGPoint(x: 0,y: 0)
let get = UIPanGestureRecognizer(target: self, action: #selector(pangectureRecognizer))
self.uiview.addGestureRecognizer(get)
//Swipe Action.
@objc func pangectureRecognizer(_ sender: UIPanGestureRecognizer){
let touchPoint = sender.location(in: self.view?.window)
if sender.state == UIGestureRecognizerState.began {
initialTouchPoint = touchPoint
} else if sender.state == UIGestureRecognizerState.changed {
if touchPoint.y - initialTouchPoint.y > 0 {
self.view.frame = CGRect(x: 0, y: touchPoint.y - initialTouchPoint.y, width: self.view.frame.size.width, height: self.view.frame.size.height)
}
} else if sender.state == UIGestureRecognizerState.ended || sender.state == UIGestureRecognizerState.cancelled {
if touchPoint.y - initialTouchPoint.y > 100 {
self.dismiss(animated: true, completion: nil)
} else {
UIView.animate(withDuration: 0.3, animations: {
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
})
}
}
}