![](/img/trans.png)
[英]How can I determine if a user has ever seen the dialog asking for push notification permission (ios)
[英]Determine if button can be seen by user
我有一個有趣的要求。 我有一個webview,當用戶刷新時,它的大小會擴大。 這很好用,但現在我試圖檢測用戶是否已滾動到頂部,以便我可以再次最小化它。
我試圖通過在webview后面放置一個圖像來做到這一點,如果用戶滾動瀏覽webview的頂部,則會發生反彈效果並且底層圖像變得可見。 我試圖使用“隱藏”屬性,認為圖像在webview下隱藏,但在webview被拉下時可見。 然而,這似乎沒有正常工作。
任何人都有關於如何檢測按鈕/圖像是否對用戶可見的任何想法?
因為UIWebView實現了UIScrollViewDelegate,它聲明符合該協議,所以您可以使用ScrollViewDidScroll
委托方法。
首先確保您的UIWebView
不在UIScrollView
重要提示:您不應在UIScrollView對象中嵌入UIWebView或UITableView對象。 如果這樣做,可能會導致意外行為,因為兩個對象的觸摸事件可能混淆和錯誤處理。
相反,您可以通過UIWebView屬性訪問UIScrollView,因為我們現在知道UIWebView基於UIScrollView。 您的視圖控制器可以實現UIScrollViewDelegate。
@interface MyViewController : UIViewController<UIScrollViewDelegate>
@end
然后你必須將webview中的scrollView屬性設置為UIScrollViewDelegate,如下所示:
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the scrollView property's delegate protocol to self. This is so that this view controller will receive the delegate methods being fired when we interact with the scrollView.
webView.scrollView.delegate = self;
}
我們只對ScrollView的委托方法之一 - scrollViewDidScroll感興趣。 然后,您可以檢測滾動視圖何時在webview中滾動,並最終有一個簡單的數學方程式,檢查scrollView是否已滾動到頂部:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView.contentOffset.y <= 0.0){
NSLog(@"TOP REACHED so do the chicken dance");
}
}
如果它是Y == 0,則查找Web視圖滾動視圖的contentOffset,這意味着用戶已向上滾動到頂部。
CGRect visibleRect;
visibleRect.origin = webView.scrollView.contentOffset;
if(visibleRect.origin.y == 0)
{
//t means that user has scrolled up to the top
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.