触摸事件(touchesMoved)不工作在UIScrollView内的UIViews
我有一个UIScrollView
内的UIView
,并且这些视图的UIViewControllers
没有接收到触摸事件。 如果我将视图从滚动视图中移出,那么它就起作用了。
UserInteraction是所有视图的默认ON,但它仍然不起作用!
这一定是可能的,我会很感激,如果有人能指出我的方向正确!
非常感谢,
添加下面的代码到实现文件然后触动移动
@interface UIScrollView(Custom) @end @implementation UIScrollView(Custom) -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; } @end
您可以使用以下方法
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)]; [panRecognizer setMinimumNumberOfTouches:1]; [panRecognizer setMaximumNumberOfTouches:1]; [panRecognizer setDelegate:self]; [yourView addGestureRecognizer:panRecognizer];
并处理它
-(void)move:(id)sender { if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateChanged){ // This will return you location in view CGPoint currentPoint = [sender locationInView:self.view]; // This will return you location in Scrollview CGPoint scrollPoint = [sender locationInView:[[sender view] superview]]; } }