Mantas Juodviršis Mantas Juodviršis - 1 year ago 102
Swift Question

UIGestureRecognizer doesnt work and makes app slow

In map view, I want to make that if user touches anywhere in the map, app stops updating location..but seems like nothing happens and it takes around 10-15 seconds for actions to work in the app ( makes app really slow and laggy ) I have been using this code:

@IBOutlet var Map: MKMapView!

let locationManager = CLLocationManager()
override func viewDidLoad() {
StopUpdate.hidden = true
Longi.hidden = true
Lati.hidden = true
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.view.addGestureRecognizer(UIGestureRecognizer(target: self, action: "tapClose"))

func tapClose(gesture: UITapGestureRecognizer){
StopUpdate.hidden = true
UpdateLocation.hidden = false

Because of the GestureRecognizer my app is slow and laggy.Any solution to this?

Answer Source

Right way to add UITapGesture

class DashVC: UIViewController, UIGestureRecognizerDelegate{

define tapgesture in viewdidload like this

let tapDashBoard = UITapGestureRecognizer(target: self, action: #selector(DashVC.DashBoardTapped(_:)))
    tapDashBoard.delegate = self

and action

    func DashBoardTapped(sender: UITapGestureRecognizer? = nil) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download