【发布时间】:2021-11-21 16:43:41
【问题描述】:
我有 2 个不同的文本字段,如果这些文本字段为空,我想隐藏按钮,并在填充时使该按钮可见。我做了一个如下等式。第一次开机没有出现这个按钮,但是我填数据的时候也没有出现。哪里错了?
var secilenLatitude = Double()
var secilenLongitude = Double()
@IBOutlet weak var isimTextField: UITextField!
@IBOutlet weak var notTextField: UITextField!
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var lokasyonuKaydet: UIButton!
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
let gestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(konumSec(gestureRecognizer:)))
mapView.addGestureRecognizer(gestureRecognizer)
let keyboardGR = UITapGestureRecognizer(target: self, action: #selector(klavyeyiKapat))
self.view.addGestureRecognizer(keyboardGR)
if isimTextField.text!.isEmpty == true && notTextField.text!.isEmpty == true {
lokasyonuKaydet.isHidden = true
} else {
lokasyonuKaydet.isHidden = false
}
}
@objc func klavyeyiKapat() {
view.endEditing(true)
}
@objc func konumSec(gestureRecognizer: UILongPressGestureRecognizer) {
if gestureRecognizer.state == .began {
let dokunulanNokta = gestureRecognizer.location(in: mapView)
let dokunulanKoordinat = mapView.convert(dokunulanNokta, toCoordinateFrom: mapView)
let annotation = MKPointAnnotation()
annotation.coordinate = dokunulanKoordinat
annotation.title = isimTextField.text
annotation.subtitle = notTextField.text
mapView.addAnnotation(annotation)
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = CLLocationCoordinate2D.init(latitude: locations[0].coordinate.latitude, longitude: locations[0].coordinate.longitude)
let span = MKCoordinateSpan.init(latitudeDelta: 0.05, longitudeDelta: 0.05)
let region = MKCoordinateRegion.init(center: location, span: span)
mapView.setRegion(region, animated: true)
}
我的故事板: Storyboard
【问题讨论】:
-
何时评估此条件?请分享更多代码
-
创建一个minimal reproducible example。我们甚至不知道您使用的 UI 框架。
-
感谢您的推荐,我再次更新了代码并添加了图像。
标签: swift