UIScrollView: single tap scrolls it to top

后端 未结 5 1813
不知归路
不知归路 2021-01-03 04:25

I have the UIScrollView with pagingEnabled set to YES, and programmatically scroll its content to bottom:

CGPoint contentOffset = scrollView.contentOffset;
c         


        
5条回答
  •  悲&欢浪女
    2021-01-03 04:57

    The following workaround did help (assume that one extends UIScrollView with a category, so 'self' refers to its instance):

    -(BOOL) scrolledToBottom
    {
        return (self.contentSize.height <= self.frame.size.height) ||
               (self.contentOffset.y == self.contentSize.height - self.frame.size.height);
    }
    

    Then, one should sometimes turn pagingEnabled off, just at the position where scroll view reaches its bottom. In the delegate (pagingEnabled is initialy on of course, since the problem occurs only when it is enabled):

    -(void) scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (scrollView.pagingEnabled == YES)
        {
            if ([scrollView scrolledToBottom] == YES)
                scrollView.pagingEnabled = NO;
        }
        else
        {
            if ([scrollView scrolledToBottom] == NO)
                scrollView.pagingEnabled = YES;
        }
    }
    

提交回复
热议问题