UIScrollView scrolling in only one direction at a time

前端 未结 4 1865
孤街浪徒
孤街浪徒 2020-12-31 02:47

I have a UIScrollView and I want it to be able to scroll in both directions (it currently does) but only one at a time. So, for instance, if you start scrolling it horizonta

4条回答
  •  忘掉有多难
    2020-12-31 03:08

    the simple way to achieve this is set the directionalLockEnabled to YES and implement the UIScrollerView delegate like this

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        if (scrollView.contentOffset.x != 0 &&
            scrollView.contentOffset.y != 0) {
            scrollView.contentOffset = CGPointMake(0, 0);
        }
    }
    

提交回复
热议问题