I am using a Edit/Done button to move an MKMapView upwards when Edit mode is selected, with the intention of display a message in an imageView at the bottom of the screen. My understanding is to change the function of this button I must use override func setEditing().
While I can get it to change from Edit to Done mode once, with the corresponding title change, I can never get it to change back to Edit mode. The result being when you just press "Done" over and over it remains "Done" and keeps moving the MKMapView up.
I want this to operate as a toggle but the process escapes me for some reason:
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: true)
if editing {
print("Are we editing NOW: \(isEditing)")
mapView.frame.origin.y = -24
editButtonItem.title = "Done"
} else {
print("Are we editing: \(isEditing)")
mapView.frame.origin.y = 64
editButtonItem.title = "Edit"
}
super.setEditing(editing, animated: true)
My attempted implementations of "isEditing" and "isEnabled" within my if/else statement haven't worked so far. What am I missing?
EDIT:
Well I came up with this approach, which works but seems clunky.
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: true)
if editing {
print("Are we editing NOW: \(isEditing)")
mapView.frame.origin.y = -24
editButtonItem.title = "Done"
} else {
print("Are we editing: \(isEditing)")
mapView.frame.origin.y = 64
editButtonItem.title = "Edit"
}
super.setEditing(editing, animated: true)
}
I am having to use 64 as a value to get the mapView to return to the bottom the super view, not exactly sure why.