我有一个UIScrollview,它在y轴上展开并调用这个委托方法:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
float yOff = scrollView.contentOffset.y;
NSLog(@"y off is %f", yOff);
}
当scrollView移动到顶部(即yOff == 0)时,它实际上在大多数手机上休息为-20px,在iPhoneX上为-44px。如何关闭此行为,这样做有什么风险?
答案 0 :(得分:2)
尝试在contentInsetAdjustmentBehavior
上设置UIScrollView
至.never
if (@available(iOS 11.0, *)) {
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
答案 1 :(得分:2)
试试这个:
#define IPHONE4 (( [ [ UIScreen mainScreen ] bounds ].size.height == 480 ) ? 1 :0)
#define IPHONE5 (( [ [ UIScreen mainScreen ] bounds ].size.height == 568 ) ? 1 :0)
#define IPHONE6 (( [ [ UIScreen mainScreen ] bounds ].size.height == 667 ) ? 1 :0)
#define IPHONE6p (( [ [ UIScreen mainScreen ] bounds ].size.height == 736 ) ? 1 :0)
#define IPHONEX (( [ [ UIScreen mainScreen ] bounds ].size.height == 812 ) ? 1 :0)
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (IPHONEX) {
scrollView.contentOffset = CGPointMake(0,44);
}else{
scrollView.contentOffset = CGPointMake(0,20);
}
}