Je veux un MKMapView
pour flouter s'il n'y a pas d'entrée dans un champ de texte en utilisant UIVisualEffectsView
sur le dessus de la carte, je veux aussi aniamte, Maintenant le shouldChangeCharactersInRange
son être appelé deux fois quand quelqu'un commence à taper et pas du tout lorsque l'utilisateur supprime tout le texte du UITextField
. Voici mon codeUITextFieldShouldChange étant appelé deux fois
import UIKit
import MapKit
import Parse
class HomeAddressViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate, UITextFieldDelegate {
let locationManager = CLLocationManager()
@IBOutlet var activityIndicator: UIActivityIndicatorView!
@IBOutlet var homeAddressField: UITextField!
@IBOutlet var homeAddressMap: MKMapView!
@IBOutlet var blurryMap: UIVisualEffectView! = UIVisualEffectView()
override func viewDidLoad() {
super.viewDidLoad()
activityIndicator.hidden = true
homeAddressField.delegate = self
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
blurAndUnblurMap()
}
func blurAndUnblurMap() {
if homeAddressField.text?.characters.count == 0 {
UIView.animateWithDuration(1, animations: {
self.blurryMap.effect = UIBlurEffect(style: .Light)
})
} else {
UIView.animateWithDuration(0.5, animations: {
self.blurryMap.effect = nil
})
}
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
blurAndUnblurMap()
return true
}
}
votre légende. Fonctionne parfaitement – Eli