UIScrollview 停留在不正确的 contentOffset(-20 px,不是 0px) [英] UIScrollview resting at incorrect contentOffset (-20 px, not 0px)

查看:38
本文介绍了UIScrollview 停留在不正确的 contentOffset(-20 px,不是 0px)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 y 轴上展开并调用此委托方法的 UIScrollview:

I have a UIScrollview that expands in the y-axis and calls this delegate method:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

    float yOff = scrollView.contentOffset.y;
    NSLog(@"y off is %f", yOff);
}

当 scrollView 移到顶部时(即 yOff == 0),它实际上在大多数手机上停留在 -20px 和 iPhoneX 上的 -44px.如何关闭这种行为,这样做有什么风险?

As the scrollView is moved to the top (ie. yOff == 0), it actually comes to rest at -20px on most phones and -44px on the iPhoneX. How do I switch this behaviour off, and what are the risks of doing so?

推荐答案

尝试将 UIScrollView 上的 contentInsetAdjustmentBehavior 设置为 .never

Try setting contentInsetAdjustmentBehavior on your UIScrollView to .never

if (@available(iOS 11.0, *)) {
    scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}

这篇关于UIScrollview 停留在不正确的 contentOffset(-20 px,不是 0px)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆