本文介绍了automaticAdjustsScrollViewInsets在iOS9中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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;

}

有效.但是问题仍然相关,这是iOS9中的错误吗?

It works. But question is still relevant, is this a bug in iOS9?

UPDATE2

在有关__iOS_9_OR_GREATER__的评论中回答问题.可能不是最有效的解决方案,但可以完成工作.

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

推荐答案

由于iOS9 automaticallyadjustsscrollviewinsets不会通过编程方式创建,因此不会更改UIScrollViewcontentInsets.

Since iOS9 automaticallyadjustsscrollviewinsets will not change UIScrollView's contentInsets if it's created programmatically.

  • a)您可以使用UITableViewController进行自动调整.
  • b)设置automaticallyadjustsscrollviewinsets并自行调整插图.
  • a) You can use UITableViewController for auto adjustments.
  • b) Set automaticallyadjustsscrollviewinsets and adjust insets by yourself.

这篇关于automaticAdjustsScrollViewInsets在iOS9中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 02:38