Mantas Juodviršis
Mantas Juodviršis

Reputation: 15

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() {
        super.viewDidLoad()
        StopUpdate.hidden = true
        Longi.hidden = true
        Lati.hidden = true
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestWhenInUseAuthorization()
        locationManager.requestLocation()
        locationManager.startUpdatingLocation()
        locationManager.stopUpdatingLocation()
    self.view.addGestureRecognizer(UIGestureRecognizer(target: self, action: "tapClose"))
}

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

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

Upvotes: 1

Views: 451

Answers (1)

Krutarth Patel
Krutarth Patel

Reputation: 3455

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
    view.addGestureRecognizer(tapDashBoard)

and action

    func DashBoardTapped(sender: UITapGestureRecognizer? = nil) {
}

Upvotes: 1

Related Questions