【发布时间】:2015-02-05 18:18:37
【问题描述】:
所以我创建了这个平移手势识别器来检测我对几个 UIBUtton 的触摸。这个想法是。我正在寻找能够在我触摸它们时将手指滑过所有按钮并触发每个按钮的能力。现在,我可以滑过所有按钮并使用此代码触发声音。有一个问题正在发生,那就是当我用 NSLog 语句替换声音文件时,我用手指在同一个按钮内所做的每一个微小动作都会非常快速地一遍又一遍地重复声音。它对最轻微的运动做出反应。
如何在手指触摸按钮后只听到一次声音,并在手指再次触摸同一个按钮时再次播放相同的声音。几乎与您在真正的钢琴上触摸或滑动手指时获得的效果一样。
谁能帮我解决这个问题?
- (void)viewDidLoad
{
[super viewDidLoad];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:pan];
}
//Method to handle the pan:
-(void)handlePanGesture:(UIPanGestureRecognizer *)gesture
{
//create a CGpoint so you know where you are touching
CGPoint touchPoint = [gesture locationInView:self.view];
//just to show you where you are touching...
NSLog(@"%@", NSStringFromCGPoint(touchPoint));
//check your button frame's individually to see if you are touching inside it
if (CGRectContainsPoint(self.button1.frame, touchPoint))
{
NSLog(@"you're panning button1");
}
else if(CGRectContainsPoint(self.button2.frame, touchPoint))
{
NSLog(@"you're panning button2");
}
else if (CGRectContainsPoint(self.button3.frame, touchPoint))
{
NSLog(@"you're panning button3");
}
【问题讨论】:
标签: objective-c xcode