我在UIView
中有一个UIScrollView
,这些视图的UIViewControllers
没有收到触摸事件。如果我从滚动视图中取出视图,那么它就可以了。
UserInteraction是所有视图的默认ON,但它仍然无效!
这一定是可能的,如果有人能指出我正确的方向,我真的很感激!
非常感谢,
答案 0 :(得分:4)
您可以使用以下方法
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]];
}
}
答案 1 :(得分:2)
将以下代码添加到实现文件中,然后触及移动
@interface UIScrollView(Custom)
@end
@implementation UIScrollView(Custom)
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
}
@end