美文网首页
UIScrollView

UIScrollView

作者: bianruifeng | 来源:发表于2020-07-17 14:41 被阅读0次

    在某些情况下(navigationBar透明的时候),系统底层对UIScrollView及基于UIScrollView 的控件 初始位置 做了偏移;

    解决方案:

    1. 设置ScrollView不自动
    [self setAutomaticallyAdjustsScrollViewInsets:NO]
    //self.automaticallyAdjustsScrollViewInsets = NO;//同上
    
    
    /*iOS11: 
    在iOS11中`UIViewController`的`automaticallyAdjustsScrollViewInsets`属性被废弃,不再起作用, 
    取而代之的是`UIScrollView`中新增的属性`contentInsetAdjustmentBehavior`
    */
    //`UITextView`继承自`UIScrollView`,所以也是设置`contentInsetAdjustmentBehavior`
    //效果同iOS11前的`self.automaticallyAdjustsScrollViewInsets = NO;`
    
    scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    
    1. 设置导航不透明
    self.navigationController.navigationBar.translucent = NO;
    
    1. 边界延伸设置为None
    self.edgesForExtendedLayout = UIRectEdgeNone;  
    //默认为UIRectEdgeAll,会向上下左右偏移,偏移到(0,0)
    //setf.extendedLayoutIncludesOpaqueBars = NO;
    //这里系统默认就是NO,如果单设EdgesForExtendedLayout无效可以试试加上这句
    

    UIScrollView+九宫格

    相关文章

      网友评论

          本文标题:UIScrollView

          本文链接:https://www.haomeiwen.com/subject/imxghktx.html