我需要從UIScrollView中獲取觸摸位置。但是,當我創建一個子類爲我的滾動視圖:在UiScrollView上檢測觸摸位置
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray *touchesArray = [touches allObjects];
UITouch *touch = (UITouch *)[touchesArray objectAtIndex:0];
CGPoint point = [touch locationInView:self];
self.position = point;}
功能touchesBegan
並不總是叫。 如果我快速刷卡,touchesBegan
永遠不會被調用,但scrollViewDidScroll
會直接調用。
我不能使用UIGesture (UITapGestureRecognizer, ...)
,因爲用戶不點擊或滑動。
是否有其他的方法來得到的UIScrollView的位置?
編輯:
感謝ThXou:https://stackoverflow.com/a/15763450/1752843
UIScrollView的子類:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
self.position = point;
return self;
}
Thx!我的代碼:' - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { self.position = point; 迴歸自我; }' – VivienCormier