Paste KVO collection content in iOS9

With the recent release of iOS 9, some updates to existing code may be required to compensate for any changes to the Apple API. Recently, it seems that they have done this so that collection views now automatically adjust the insertion of content when the keyboard appears. This is useful for people who do not handle this manually and do not support multiple versions of the OS. In my application, it caused a little headache. I finally found a solution using KVO to tell me when the system changes the earbuds, and I react accordingly, everything works fine, except in the case of a single edge.

If I show the keyboard and then try to return to the navigation stack using an interactive scrolling that calls beginAppearanceTransition:animated: but then cancel it and then exit the keyboard side to resign as the first responder, the system suddenly decides that it does not automatically update my inserts, and my KVO never starts to insert content, the keyboard disappears, but the insertion of the contents does not decrease, which leads to its incorrect display ... if, however, I click on the text field, causing the viaturu to show again, what if he decides to do it automatically update again.

Does anyone have any idea why he is ignoring my first rejection of the keyboard after canceling the interactive transition to update my earbuds?

EDIT

The need to return to this, as the team feels that it is too fragile and hacky, and after playing with it to find out how they handle the same case, they do not seem to have to deal with an erroneous call from nowhere. So I subclassed UICollectionView and redefined the setContentInset function just to find the calling call here

IMG

Except the stack trace is not particularly useful at the moment, does anyone have any ideas?

+5
source share
1 answer

It does not seem that the answer is not suitable, and other people have encountered this problem, since here is my current solution.

So, after adding an observer for the contentInset , I have the following function.

 static bool _willSystemUpdateCollectionViewInset = NO; static bool _willCustomKeyboardViewUpdateCollectionViewInset = NO; static bool _didCancelDismissInteraction = NO; - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { if ([keyPath isEqualToString:NSStringFromSelector(@selector(contentInset))]) { id oldNumber = change[@"old"]; id newNumber = change[@"new"]; if (_willSystemUpdateCollectionViewInset) { _willSystemUpdateCollectionViewInset = NO; UICollectionView *collectionView = (UICollectionView*)object; UIEdgeInsets insets = collectionView.contentInset; insets.bottom = [oldNumber UIEdgeInsetsValue].bottom; [collectionView setContentInset:insets]; } else if (_willCustomKeyboardViewUpdateCollectionViewInset) { _willCustomKeyboardViewUpdateCollectionViewInset = NO; [self updateScrollViewInsets]; } if ([newNumber UIEdgeInsetsValue].bottom > [oldNumber UIEdgeInsetsValue].bottom ) [_messageViewController scrollCollectionViewToBottom:NO]; } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } } 

Thus, the keyboard that displays or hides the _willSystemUpdateCollectionViewInset flag is set to YES, and the above function substantially negates the change the system makes automatically.

+1
source

Source: https://habr.com/ru/post/1232239/


All Articles