尝试在scrollview的子视图中制作一些可拖动的图像。但没有任何反应。任何人都有任何想法为什么handlePan中的断点从未被击中? :'(谢谢,如果你能帮忙的话!
-(void) viewWillAppear:(BOOL)animated
{
twView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"twitter"]];
[self.springView addSubview:twView];
[twView setFrame:CGRectMake(100, 100, 60, 60)];
fbView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"facebook"]];
[self.springView addSubview:fbView];
[fbView setFrame:CGRectMake(200, 200, 60, 60)];
g1 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[twView addGestureRecognizer:g1];
g1.delegate = self;
g2 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[fbView addGestureRecognizer:g2];
g2.delegate = self;
}
-(void)handlePan:(UIPanGestureRecognizer *)gesture
{
... do amazing things
}
答案 0 :(得分:2)
根据你在这里的内容,它可能是两件事之一。您的图片视图未将userInteractionEnabled
设置为“是”,或者图片视图顶部还有另一个视图阻止手势。
答案 1 :(得分:2)
UIScrollView子类的内置平移手势识别器可能正在截取手势。
确保您的视图控制器实现UIGestureRecognizerDelegate
协议并实现
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
答案 2 :(得分:1)
另一件对我有帮助的事情是手势识别器集
UITapGestureRecognizer *loginTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(loginButtonAction)];
loginTap.delegate = self;
[self.loginButton setUserInteractionEnabled:YES];
[self.loginButton addGestureRecognizer:self.loginTap];
在将委托分配给self后,它将在委托方法中接收调用