问题
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);
}
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?
回答1:
Try setting contentInsetAdjustmentBehavior
on your UIScrollView
to .never
if (@available(iOS 11.0, *)) {
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
回答2:
Try this one:
#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);
}
}
来源:https://stackoverflow.com/questions/48319873/uiscrollview-resting-at-incorrect-contentoffset-20-px-not-0px