Swipe edge to dismiss resets UICollectionViewController bottom inset

tldr: Swipe edge to pop UICollectionViewController with inputAccessoryView resets contentInset.bottom to 0 in super.viewWillAppear. Should I block super.viewWillAppear?


I am working on UICollectionViewController and inputAccessoryView and contentInset resets at swipe edge to pop.
Since iOS 9, UICollectionViewController automatically adjust its contentInset with respect to inputAccessoryView and keyboard on screen. This makes life a lot easier and iOS does a good job with it too. UICollectionView contentInset bottom value changes as keyboard shift up and down on the screen as well as when keyboard is undocked and split.

However, I recently ran into a tiny but very annoying issue:
If the UICollectionViewController is swiped from the edge to go back, but the edge swipe gesture is cancelled half way and the UICollectionViewController bounces back, its contentInset bottom value is set to 0. =(
While debugging this, i found out the change happens during super.viewWillAppear after the edge swipe gesture is cancelled. its also strange to me that viewWillAppear is called even though the view has already appeared and is /on/ the screen.
Another important fact i found out while debugging is that, in iOS 11, it is /not/ the contentInset that is set, but rather the adjustedContentInset, even on non-iPhoneX devices. According to Apple Doc, adjustedContentInset is the contentInset of the scrollView reflected by the safe area. The thing is that non-iPhoneX bottom safe area is 0:
Testing with iPhone 8 on iOS 11:
contenInset: (0, 0, 0, 0).
safeArea: (20, 0, 0, 0). 20 is the status bar height.
adjustedContentInset: (20, 0, 50, 0). 50 is the inputAccessoryViewHeight.

I came up with a hacky way to prevent the contentInset(< iOS 11) and adjustedContentInset(iOS 11) from being set to 0 by preventing super.viewWillAppear from being called if the UICollectionViewController's view is already on the screen.
This solution is obviously as hacky as it is dirty because it intervenes with the controller’s life cycle.

Does any one have any other ways to go about this issue?


Thanks in advance!

Powered by WPeMatico

You may also like...

Comments are closed.