特定の uiwebview がページ上に表示されるたびにメソッドを呼び出す方法について何か考えはありますか? 上にスクロールできないようにするには?この機能は、ページをスマートな方法で更新できると便利です。
/エリック
特定の uiwebview がページ上に表示されるたびにメソッドを呼び出す方法について何か考えはありますか? 上にスクロールできないようにするには?この機能は、ページをスマートな方法で更新できると便利です。
/エリック
次のようなものを使用できます。
.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];
それでもうまくいかない場合は、お知らせください。
UIWebView
プロパティを持っていscrollView
ます。これはUIScrollView
、デリゲートに必要なオブジェクトを設定します。
@property(nonatomic, assign) id<UIScrollViewDelegate> delegate
これで、すべてのデリゲート コールバックを取得できます。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView