In my app I have lots of VCs with scrollviews of all kinds (table, collection, etc.). All of them appear inside NavigationController and I used .automaticallyadjustsscrollviewinsets
property of VC to prevent content from going under the NavigationBar. It works fine prior to iOS9.
I've updated my test iPhone to iOS9 yesterday and noticed that all scrollviews now does not have proper insets. I've updated XCode to latest version (7.0) and rebuilt the app - no effect. I've checked on the other device, which is still running iOS8.x - insets work correctly. I looked through iOS9 sdk changelogs and didn't find anything related to my problem. Is this a bug or a new behaviour? Anyone else having this problem? Possible solutions?
UPDATE1
I've came up with quick fix:
if (__iOS_9_OR_GREATER__) {
CGFloat topInset = 20;
if (self.navigationController) {
topInset += self.navigationController.navigationBar.bounds.size.height;
}
UIEdgeInsets insets = UIEdgeInsetsMake(topInset, 0, 0, 0);
self.collectionView.contentInset = insets;
self.collectionView.scrollIndicatorInsets = insets;
}
It works. But question is still relevant, is this a bug in iOS9?
UPDATE2
Answering the question in the comments about __iOS_9_OR_GREATER__
. Probably not the most efficient solution, but gets the job done.
#import <Foundation/Foundation.h>
#define __iOS_9_OR_GREATER__ [NKOSVersionCheck isMajorOSVersionAtLeast:9]
@interface NKOSVersionCheck : NSObject
+ (BOOL)isMajorOSVersionAtLeast:(NSUInteger)version;
@end
#import "NKOSVersionCheck.h"
@implementation NKOSVersionCheck
NSOperatingSystemVersion _majorOSVersion(int version) {
NSOperatingSystemVersion iOS_x;
iOS_x.majorVersion = version;
iOS_x.minorVersion = 0;
iOS_x.patchVersion = 0;
return iOS_x;
}
+ (BOOL)isMajorOSVersionAtLeast:(NSUInteger)version {
return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:_majorOSVersion(9)];
}
@end
Since iOS9
automaticallyadjustsscrollviewinsets
will not changeUIScrollView
'scontentInsets
if it's created programmatically.UITableViewController
for auto adjustments.automaticallyadjustsscrollviewinsets
and adjust insets by yourself.