AutomaticallyAdjustsScrollViewInsets not working in iOS9

In my application, I have many VCs with scrollviews of all kinds (table, collection, etc.). They all appear inside the NavigationController, and I used the property .automaticallyadjustsscrollviewinsetsfor VC to prevent the content from moving within the NavigationBar. It works great until iOS9.

I upgraded my test iPhone to iOS9 yesterday and noticed that now all scrollviews don't have the right attachments. I updated Xcode to the latest version (7.0) and rebuilt the application - no effect. I checked on another device that is still running iOS8.x - the inserts are working correctly. I looked through the iOS9 sdk changelogs and did not find anything related to my problem. Is this a bug or a new behavior? Does anyone else have this problem? Possible solutions?

Update1

I came up with a 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 the question is still relevant, is this a bug in iOS9?

UPDATE2

Answering the question in the comments to __iOS_9_OR_GREATER__. This is probably not the most effective solution, but it does its job.

#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
+4
source share
1 answer

Since iOS9 automaticallyadjustsscrollviewinsetswill not change UIScrollView contentInsetsif it is created programmatically.

  • a) You can use UITableViewControllerto automatically configure.
  • b) Install automaticallyadjustsscrollviewinsetsand customize the inserts.
+2
source

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


All Articles