I’m working on an iOS app where I have an AnyArtboardEvent method that pushes snapshots into my undo/redo stack.
Here’s a simplified version of it:
func AnyArtboardEvent(mergedImaged: UIImage = UIImage()) {
self.undoRedo?.Add(value: self.SlotViewsToCollection(mergedImage: mergedImaged))
self.UpdateControllerForActiveSlot()
}
The Add method in my UndoRedo class just appends values to a collection (no recursion there).
func Add(value: SlotViewCollection) {
var pointerTemp: Int = self.pointer
pointerTemp = pointerTemp + 1
self.pointer = pointerTemp
self.CheckValueAtIndex(value)
self.EnsureCollectionSize()
}
Issue is that when user finishes interacting with a slider, I call AnyArtboardEvent inside the .ended phase of my touch event handler:
if let touchEvent = event.allTouches?.first {
switch touchEvent.phase {
case .ended:
self.isAnyThingChange = true
self.AnyArtboardEvent() // <-- called here
self.CurrentActiveSlot?.TextLabel?.InitCaLayer(parentView: self)
default:
break
}
}
But after debugging:
When the slider interaction ends, AnyArtboardEvent is called three times.
The first call is expected, but the second and third calls happen immediately afterward (without me explicitly calling them).
I added a symbolic breakpoint and confirmed that all three calls originate from this .ended block.
I also checked the InitCaLayer method (which adds a border CAShapeLayer), but it doesn’t call AnyArtboardEvent.
So far, I couldn’t find anything in my code that would cause AnyArtboardEvent to run multiple times.
Is it possible that touchesEnded / .ended phase is firing multiple times for the slider gesture?
Or could adding layers (CAShapeLayer) indirectly trigger layout passes that fire the touch event handler again?
How can I ensure AnyArtboardEvent is called only once per slider interaction?
AnyArtboardEvent()
being called from elsewhere in your code? Put aprint("ended") after
self.isAnyThingChange = true` and confirm that it's really being triggered 3 times.