问题
I'm trying to handle the three-finger gesture with a custom undo manager. Using the default undo manager provided by the window, resolved via the UIResponder chain works flawlessly. As soon as I try to use an own undo manager in a view controller I run into issues. (Background: I want to switch between different managers depending on the state of the view, so I can't use the single undo manager provided by the window.)
What I did:
- override
undoManager
in my view controller and return an own instance - override
canBecomeFirstResponder
and returntrue
- set the VC to be the first responder on
viewDidAppear
(I also tried different places for that)
What I observe:
- three-finger swipes do not trigger
undo
on my undo manager, but on the window's - the shake-to-undo gesture does trigger
undo
on my VC's undo manager
Now the funny part:
If I add a UITextField
(or UITextView
) to my view, tell it to become the first responder and immediately after let my VC become first responder again, the 3-finger gesture works! So it seems the text field is telling the system something when it becomes first responder that tells the 3-finger gesture observer to not use the window's undo manager. And when resigning first responder, the duty falls correctly to my VC.
Does anyone have an idea what I'm missing here?
来源:https://stackoverflow.com/questions/58270293/three-finger-undo-gesture-with-custom-undo-manger