Xcode 4.5确定uiwebview是否可以向上滚动

时间:2013-02-12 15:41:54

标签: uiwebview uiscrollview uikit

你是否有任何想法如何在每次某个uiwebview一直在页面上调用方法,即。这样就无法向上滚动?这个功能非常适合以智能方式刷新页面。

/埃里克

2 个答案:

答案 0 :(得分:1)

您可以使用以下内容:

在.h中,您的代码应该类似于:

@interface iSafeViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate>

然后在.m

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //The webview is is scrolling
    float scrollViewHeight = scrollView.frame.size.height;
    float scrollContentSizeHeight = scrollView.contentSize.height;
    float scrollOffset = scrollView.contentOffset.y;

    if (scrollOffset <= 1)
    {
        // then we are at the top

    }
    else if (scrollOffset + scrollViewHeight >= scrollContentSizeHeight - 1)
    {
        // then we are at the end

    }
    else
    {
        //We are somewhere in the middle
    }
}

您需要设置webView的scrollView委托,但是这样:

[webView.scrollView setDelegate:self];

如果这不起作用,请告诉我。

答案 1 :(得分:0)

UIWebView具有scrollView属性。这是UIScrollView设置您想要委托的对象:

@property(nonatomic, assign) id<UIScrollViewDelegate> delegate

现在您将获得所有委托回调:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView