Three-finger undo gesture with custom undo manger

霸气de小男生 提交于 2019-12-08 05:34:19

问题


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 return true
  • 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!