ContinueTrackingWithTouch:withEvent: 方法没有被调用?
我有一个自定义 UIView 类。在该视图内,有一个图像视图。 (我正在从头开始制作 UISlider)。
我试图让图像视图(滑块的拇指)在视图上移动。下面是 UIView 类中的代码
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchPoint = [touch locationInView:self];
if ( CGRectContainsPoint(self.thumb.frame, touchPoint))
self.thumb.center = CGPointMake(touchPoint.x, self.thumb.center.y);
return YES;
}
当我将手指放在滑块的拇指上并尝试拖动它时,没有任何反应。然而,当我触摸滑块的拇指外侧时,将手指拖到拇指上不放手,然后尝试拖动拇指,效果很好。
如何修改我的代码,以便当有人握住拇指并尝试拖动它时调用该方法?
I have a custom UIView class. Inside that view, there is an image view. (I'm making a UISlider from scratch).
I am trying to get the image view -- the thumb of the slider -- to move across the view. Below is the code from the UIView class
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchPoint = [touch locationInView:self];
if ( CGRectContainsPoint(self.thumb.frame, touchPoint))
self.thumb.center = CGPointMake(touchPoint.x, self.thumb.center.y);
return YES;
}
When I place my finger on the thumb of the slider and try to drag it, nothing happens. However, when I touch outside the thumb of the slider, drag my finger to the thumb without letting go, and then try dragging the thumb, it works fine.
How can I modify my code so that the method will be called when someone holds the thumb and tries to drag it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,您在图像视图上启用了用户交互,这反过来又不会将触摸事件中继到支持逻辑视图。做这样的事情:
将其放入您正在使用的任何初始化方法中,拇指视图将不再中断触摸事件。
My guess is that you have user interaction enabled on your image view, which is in turn not relaying the touch events to the backing logic view. Do something like this:
Put that in whatever init method you are using and the thumb view will not interrupt the touch events anymore.