iOS 11 中scrollview布局往下偏移问题automaticallyAdjustsScrollViewInsets、contentInsetAdjustmentBehavior(iOS 11

//
//  ViewController.m
//

#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong)UIScrollView * scrollView;
@end

@implementation ViewController

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.frame = CGRectMake(0, 0, 300, 300);
    }
    return _scrollView;
}

- (void)viewDidLoad {
    self.scrollView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.scrollView];
    //‼️=============判断系统版本
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        NSLog(@"11.0f");
        } else {
            self.automaticallyAdjustsScrollViewInsets = NO;
            NSLog(@"10f");
        }
}

@end

你可能感兴趣的:(UI布局,基本控件)