MKMapView
如果文本字段中没有条目,我想通过UIVisualEffectsView
在地图顶部使用来模糊,我也希望它可以显示,现在shouldChangeCharactersInRange
当有人开始输入时它会被调用两次,而当用户删除所有文本时根本不会调用从UITextField
. 这是我的代码
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
}
}