简体   繁体   中英

I know how to disable bouncing of uitableview on top only - but how can I do it only on the bottom?

I managed to disable bouncing effect when user scrolls to the top. I would like to reverse it somehow so that the bouncing effect is disabled on the bottom. Could you help me with modifying my code for that purpose?

var lastY: CGFloat = 0.0

func scrollViewDidScroll(scrollView: UIScrollView) {
    let currentY = scrollView.contentOffset.y
    let currentBottomY = scrollView.frame.size.height + currentY
    if currentY > lastY {
        //"scrolling down"
        tableView.bounces = true
    } else {
        //"scrolling up"
        // Check that we are not in bottom bounce
        if currentBottomY < scrollView.contentSize.height + scrollView.contentInset.bottom {
            tableView.bounces = false
        }
    }
    lastY = scrollView.contentOffset.y
}

You can try this code

override func scrollViewDidScroll(scrollView: UIScrollView)

{
   if scrollView.contentOffset.y <= 0  
     {
        scrollView.contentOffset = CGPointZero
     }
}

Did you try setting bounce and VerticalBounce property to NO .

You can set these properties programatically like

In Swift

tableView.bounces = false
tableView.alwaysBounceVertical = false

In Objective-C

tableView.bounces = NO;
tableView.alwaysBounceVertical = NO;

OR

if you want to do it from Storyboard . Make you tableview setting like below :

在此处输入图片说明

May following snippet help you :

override func scrollViewDidScroll(scrollView: UIScrollView) {
    if scrollView.contentSize.height > self.view.frame.size.height && scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height {
        scrollView.setContentOffset(CGPoint(x: scrollView.contentOffset.x, y: scrollView.contentSize.height - scrollView.frame.size.height), animated: false)
    }
}

Try this:

 func scrollViewDidScroll(_ scrollView: UIScrollView) {
            if scrollView == tableView {
                if (self.tableView.contentOffset.y >= (self.tableView.contentSize.height - self.tableView.bounds.size.height))
                {
                    scrollView.contentOffset = CGPoint(x: 0, y: (self.tableView.contentSize.height - self.tableView.bounds.size.height))
                }
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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