简体   繁体   English

UIScrollView 1D弹跳但2D滚动

[英]UIScrollView 1D Bouncing but 2D Scrolling

The project I'm currently working requires that a UIScrollView to scroll vertically and horizontally, however, it must only bounce vertically. 我当前正在工作的项目要求UIScrollView可以垂直和水平滚动,但是,它只能垂直反弹。 Is this possible? 这可能吗? I noticed that there is a verticalBouncing and horizontalBouncing property in the declaration, could that be the answer? 我注意到声明中有一个verticalBouncinghorizontalBouncing属性,这可能是答案吗?

You cannot access @package ivars directly. 您不能直接访问@package ivars。 However, you can register yourself as delegate of UIScrollView and implemenet this code 但是,您可以将自己注册为UIScrollView委托并实现此代码

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float maxX = scrollView.contentSize.width - scrollView.frame.size.width;

    CGPoint offset = scrollView.contentOffset;
    offset.x = MAX(MIN(maxX, offset.x), 0);
    scrollView.contentOffset = offset;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM