gpt4 book ai didi

iphone - UIScrollView 触摸开始

转载 作者:行者123 更新时间:2023-12-03 18:29:15 25 4
gpt4 key购买 nike

所以我想做的就是当用户触摸 UIScrollView 时播放声音。UIScrollViewDelegate有scrollViewWillBeginDragging:方法,但它只在touchMoved时被调用。我希望它在 touchBegan 时被调用。

尝试touchesBegan:withEvent:但它没有收到任何触摸。有人知道吗?

最佳答案

改用点击手势识别器:

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touch)];
[recognizer setNumberOfTapsRequired:1];
[recognizer setNumberOfTouchesRequired:1];
[scrollView addGestureRecognizer:recognizer];

或者

创建 UIScrollView 的子类并实现所有

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesBegan: touches withEvent:event];
}
else{
[super touchesEnded: touches withEvent: event];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesBegan: touches withEvent:event];
}
else{
[super touchesEnded: touches withEvent: event];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesBegan: touches withEvent:event];
}
else{
[super touchesEnded: touches withEvent: event];
}
}

关于iphone - UIScrollView 触摸开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1685956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com