Search code examples
iosuikit

iOS clicks through status bar after hiding


I added these 2 keys to hide status bar:

Status bar is initially hidden = YES
View controller-based status bar appearance = NO

It works great, but I realize that when clicking on the status bar area, we can actually click through the view underneath.

I have a UICollectionView behind the status bar area, and I can actually click on the collection cell. In the picture below, Cell #12 is right above Cell #16, and we can actually tap on upper right corner to trigger didSelectCell(atIndexPath.

How do I disable this "click through" behavior, and bring back the "auto scroll to top" behavior when tapping on status bar?

enter image description here


Solution

  • Try setting the UICollectionView top constraint to be constrained to the parent view safeAreaTopAnchor instead of the parent view topAnchor. That way you have the UICollectionView out of the way of the statusbar