0

My question is the same as this question, but has one difference. When I scroll to top refresh my website, I want stop bouncing only to the end of the bottom scroll. How do I do this?

Community
  • 1
  • 1
Farid Valiyev
  • 203
  • 5
  • 20
  • You should be able to set `contentOffset` in scrollview's `scrollviewdidscroll` – zc246 Apr 04 '16 at 16:28
  • How? Can you explain me with a little code? – Farid Valiyev Apr 04 '16 at 16:36
  • @Pyro sorry, my browser very slow, I want click to vote up, browser crashed and I clicked many times)) Accepted you answer again. Thanks for answer, you solution helped me :) Have a good day. – Farid Valiyev Apr 15 '16 at 14:03
  • Please have a search yourself first after being given suggestions, instead of immediately ask for code when you ask a question in the future. – zc246 Apr 15 '16 at 14:49

3 Answers3

7

You can try like this :

override func viewDidLoad() {
    super.viewDidLoad()

    webview.scrollView.delegate = self

}

func scrollViewDidScroll(scrollView: UIScrollView) {

    if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
        scrollView.setContentOffset(CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height), animated: false)
    }   
}

Set the delegate of your webview and set the content offset of the webview's scrollview

Ref taken from: https://stackoverflow.com/a/14084747/4557505

Community
  • 1
  • 1
HardikDG
  • 5,892
  • 2
  • 26
  • 55
5

Personally in Xcode 7.3 in Swift, I Simply add this in the viewDidLoad Function:

UIWebview.scrollView.bounces = false;
melMass
  • 3,813
  • 1
  • 31
  • 30
  • What would be the equivalent command in obj-c? I'm using [cordova](https://cordova.apache.org/docs/en/latest/) and it's still relying on obj-c for ios. – Uche Ozoemena Jan 20 '22 at 00:17
  • @UcheOzoemena I'm not too familiar with UIKit on obj-c, but the doc states it's an `@property`: https://developer.apple.com/documentation/uikit/uiscrollview/1619420-bounces?language=objc – melMass Jan 20 '22 at 22:08
1

I think you can also set the scrollview's bounces

like this,It's simple

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.y > 0) {
        scrollView.bounces = NO;
    }else{
        scrollView.bounces = YES;
    }
}
vook
  • 11
  • 1