2013-02-12 67 views

回答

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];

如果不工作讓我知道。

+0

它的偉大工程,謝謝!有一件事,我得到這個問題:發送'FirstViewController * const __strong'到不兼容類型'id '的參數。你知道我如何擺脫它嗎?它在「[webView.scrollView setDelegate:self];」在.m文件中。 – user1981282 2013-02-12 16:16:35

+0

哦,是的,在你的頭文件中,添加UIScrollViewDelegate。爲了清晰起見,我會編輯我的asnwer。 – Josiah 2013-02-12 16:33:04

+0

再次感謝您!這在iPad上非常好,但在iPhone上卻不行,你明白爲什麼?我有相同的標題和實施文件鏈接到iPhone和iPad,但有兩個不同的uiwebviews。 – user1981282 2013-02-12 20:37:56

0

UIWebView有一個scrollView財產。這是UIScrollView組要委託什麼都反對:

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

現在,您將得到所有的委託回調:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView 
相關問題