【问题标题】:automaticallyAdjustsScrollViewInsets doesn't work in iOS9automaticAdjustsScrollViewInsets 在 iOS9 中不起作用
【发布时间】:2015-09-18 10:48:01
【问题描述】:

在我的应用程序中,我有很多带有各种滚动视图(表格、集合等)的 VC。它们都出现在 NavigationController 中,我使用了 VC 的 .automaticallyadjustsscrollviewinsets 属性来防止内容进入 NavigationBar 下方。在 iOS9 之前它可以正常工作。

我昨天将我的测试 iPhone 更新到 iOS9,并注意到所有滚动视图现在都没有正确的插图。我已将 XCode 更新到最新版本 (7.0) 并重建了应用程序 - 没有效果。我检查了另一台仍在运行 iOS8.x 的设备 - 插入工作正常。我查看了 iOS9 sdk 更改日志,没有发现任何与我的问题相关的内容。这是错误还是新行为?还有其他人有这个问题吗?可能的解决方案?

更新1

我想出了快速解决方法:

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;

}

它有效。但是问题仍然相关,这是iOS9中的一个错误吗?

更新2

回答cmets中关于__iOS_9_OR_GREATER__的问题。可能不是最有效的解决方案,但可以完成工作。

#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

【问题讨论】:

  • 您是否尝试将 .automaticallyadjustsscrollviewinsets 设置为否?
  • @DheerajSingh 是的。 ScrollView 在 iOS8 上开始进入导航栏,在 iOS9 上没有任何变化。
  • @NKorotkov 你用什么来确定_iOS_9_OR_GREATER
  • @NickWargnier 我用__iOS_9_OR_GREATER_的定义更新了我的问题

标签: uikit ios9


【解决方案1】:

由于 iOS9 automaticallyadjustsscrollviewinsets 不会更改 UIScrollViewcontentInsets,如果它是通过编程方式创建的。

  • a) 您可以使用UITableViewController 进行自动调整。
  • b) 设置automaticallyadjustsscrollviewinsets 并自行调整插图。

【讨论】:

  • a) UITableViewController 在我的情况下不是一个选项,因为它使视图层次结构复杂化。 automaticallyAdjustsScrollViewInsets 已在情节提要中设置,在 iOS9 中不起作用。 b)是的,我几乎采用了手动解决方案。但为什么他们首先改变了这一点?它曾经完美地工作。
  • @NKorotkov 你应该在故事板中添加滚动视图,而不仅仅是设置这个 bool 属性。
  • 我做到了。我的 TableViews 和 CollectionViews 是通过故事板添加的。
  • @TimurBernikowich 这是您的观察结果,还是 Apple 在其变更日志中声明了这一点?如果是后来的情况,你能给我一个链接吗?
  • @sarunw 这是我的观察。但是网上有几个链接:openradar.me/22106545
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 1970-01-01
  • 1970-01-01
  • 2016-01-21
  • 2016-01-25
  • 2015-12-19
  • 2016-01-09
相关资源
最近更新 更多