問題描述
我有一個帶有幾個子視圖的 UIScrollView
等等.我也是scrollView的delegate
,并實現了- (void)scrollViewDidScroll:(UIScrollView *)scrollView
.在我的卷軸下面有另一個視圖.
I have an UIScrollView
with a few subviews and so on. I am also the scrollView's delegate
and have implemented the - (void)scrollViewDidScroll:(UIScrollView *)scrollView
. Underneath my scroll there is another view.
如果滾動視圖的 contentOffset
在 x 軸上低于 50px,我想顯示該視圖,重置"滾動視圖的 contentOffset
并取消當前的滾動視圖手勢,以便用戶不會在新視圖出現時操作其內容.
I want to show that view if the scrollView's contentOffset
goes under 50px on x axis, "reset" scrollView's contentOffset
and cancel the current scrollView gesture so that the user wont manipulate its content when the new view appears.
我已經實現了這樣的方法:
I have implemented the method like so:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.x < -50)
{
scrollView.contentOffset = CGPointZero;
[self showBackView];
//here I want to cancel the current touch on the scrollview since it keeps scrolling if I drag my finger
}
}
我曾嘗試將 userInteractionEnabled
屬性設置為 NO
但只有在觸摸結束后才會生效.而且我嘗試了許多其他屬性,但似乎都沒有.
I have tried to set the userInteractionEnabled
property to NO
but it takes effect only after the touch has ended. And I have tried a bunch of other properties but none seems to work.
我該如何解決這個問題?
How can I fix this?
推薦答案
嘗試禁用滾動視圖的 panGestureRecognizer
(然后重新啟用它).這將取消識別器的當前會話:
Try disabling the panGestureRecognizer
for the scroll view (and then reenabling it). This will cancel the current session of the recogniser:
self.scrollView.panGestureRecognizer.enabled = NO;
self.scrollView.panGestureRecognizer.enabled = YES;
斯威夫特
self.scrollView.panGestureRecognizer.isEnabled = false
self.scrollView.panGestureRecognizer.isEnabled = true
這篇關于取消當前 UIScrollView 觸摸的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!