問題描述
textViewDidBeginEditing 由於縮放而未觸發 (textViewDidBeginEditing not firing due to zoom)
I have a UIViewController subclass that is acting as the delegate for a UITextView. I implemented textViewDidBeginEditing to display a 'Done' button to dismiss the text view... all is well... except that when the text view has text and is not in edit mode, if a user holds a finger in the text view causing the text to be zoomed with the magnifying glass, the keyboard appears but textViewDidBeginEditing does not fire.
I have tried to work around this by implementing the UIScrollView delegate methods viewForZoomingInScrollView and scrollViewDidEndZooming but I can't get those to fire for me at all.
I tried playing with the minimumZoomScale and maximumZoomScale properties to disable zooming... to no avail.
At this point I have no idea what to try next or if my failure catching the UIScrollView delegate methods is related to my main issue. I'm uncertain what code I could post that would be of value... the textViewDidBeginEditing method is very minimal and works fine in normal circumstances. The UITextView delegate assignment is made with a connection in Interface Builder to the controller (File Owner).
參考解法
方法 1:
A workaround might be to register to the keyboard notifications. Once you do will know exactly when the keyboard is displayed.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardNotificationShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardNotificationHide:) name:UIKeyboardWillHideNotification object:nil];
(by shawn、Ron Srebro)