Iphone 触摸事件(触摸移动)在UIScrollView内部的UIView上不起作用
我在Iphone 触摸事件(触摸移动)在UIScrollView内部的UIView上不起作用,iphone,ios,uiviewcontroller,uiscrollview,uitouch,Iphone,Ios,Uiviewcontroller,Uiscrollview,Uitouch,我在uicrollview中有一个UIView,这些视图的UIViewControllers没有接收触摸事件。如果我将视图从滚动视图中移除,那么它会工作 UserInteraction是所有视图的默认选项,但它仍然不工作 这一定是可能的,如果有人能给我指出正确的方向,我将非常感激 非常感谢,将以下代码添加到实现文件中,然后单击 @interface UIScrollView(Custom) @end @implementation UIScrollView(Custom)
uicrollview
中有一个UIView
,这些视图的UIViewControllers
没有接收触摸事件。如果我将视图从滚动视图中移除,那么它会工作
UserInteraction是所有视图的默认选项,但它仍然不工作
这一定是可能的,如果有人能给我指出正确的方向,我将非常感激
非常感谢,将以下代码添加到实现文件中,然后单击
@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]];
}
}
为什么不使用手势识别器来识别sameI特别需要的TouchsMoved方法调用,哪种手势适用于此?TouchsMoved不适用于UIScrollView@Zeeshan希望下面的代码能帮助你谢谢@ShashankKulshrestha@Vinodh. 你还可以提一下,为什么要这么做,这样对新手理解发生了什么会有帮助。我相信,当uiview添加到scrollview时,scrollview会接收所有触摸事件,因此不会调用touchesStart、touchesMoved。如果我错了,请纠正我。