1

特定の uiwebview がページ上に表示されるたびにメソッドを呼び出す方法について何か考えはありますか? 上にスクロールできないようにするには?この機能は、ページをスマートな方法で更新できると便利です。

/エリック

4

2 に答える 2

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

それでもうまくいかない場合は、お知らせください。

于 2013-02-12T15:46:26.353 に答える
0

UIWebViewプロパティを持っていscrollViewます。これはUIScrollView、デリゲートに必要なオブジェクトを設定します。

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

これで、すべてのデリゲート コールバックを取得できます。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
于 2013-02-12T15:46:50.693 に答える