1

所以我有一个由 UIButtons 组成的键盘,每个 UIButtons 每个按钮都包含一个单独的声音。当用户点击按钮时声音会播放,但我想知道当用户滑动在屏幕上拖动他们的触摸时,我如何才能播放它,就像钢琴滑奏一样,而不会将手指从屏幕上移开。

4

1 回答 1

1

您需要添加一个 PanGestureRecognizer。假设您将所有按钮都安排在 TableView 中。然后你需要从 UIPanGestureRecognizer 中识别出被触摸的 Cell。

将 UIPanGestureRecognizer 添加到 Storyboard 中的 UITableView 或通过在 ViewDidLoad() 中编写以下代码

    UIPanGestureRecognizer *pRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panning:)];
    [self.tableView addGestureRecognizer:pRecognizer];

然后在平移方法

    -(void)panning:(UIPanGestureRecognizer *)recognizer
    {
       CGPoint panLocation = [recognizer locationInView:self.tableView];
       NSIndexPath indexPath = [self.tableView indexPathForRowAtPoint:panLocation];

       //Get the cell from the table view
       UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
       **call TouchupInside event of your Key here**
    } 

因此,现在您可以在用户平移您的按键时为所有按键播放声音。

于 2016-01-09T04:40:59.843 回答