繁体   English   中英

检测长按和音量按钮 - iOS

[英]Detect long and short press of volume button - iOS

我一直在四处寻找疯子。 我需要在音量按钮长按和短按(如Snapchat,短按拍照,长按录制视频)上进行自定义操作但是失败了。

我使用了https://github.com/jpsim/JPSVolumeButtonHandler ,它允许我检测音量按钮按下事件。 但经过非常努力的尝试后,我没有察觉到它的长按和何时短按。

另请参阅检测iPhone音量按钮保持? (iOS 8)

我的代码

//Volume button handler

self.volumeButtonHandler = [JPSVolumeButtonHandler volumeButtonHandlerWithUpBlock:^{
        // Volume Up Button Pressed
        [self onVolumeUp];
    } downBlock:^{
        // Volume Down Button Pressed
    }];

-(void)onVolumeUp {
    if(self.volButtonTimer) {
        secondsElapsed = 1; //To detect long press
        [self.volButtonTimer invalidate];
    }
    self.volButtonTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
                                                  target:self
                                                selector:@selector(onTimerFire)
                                                userInfo:nil
                                                 repeats:NO];

}

-(void)onTimerFire {
    NSLog(@"Long Press %d",secondsElapsed);
    if (secondsElapsed > 1)
    {
        //Do Something
    }
    else secondsElapsed = 0;

}

我需要帮助。 搜索遍布谷歌但失败了。 如果Snapchat正在这样做,意味着它可行。

谢谢

我现在面临同样的问题。 我能够发现的是,如果Apple改变了一些基本的硬件功能,它将拒绝你的应用程序。 请访问此链接: https//developer.apple.com/app-store/review/guidelines/ 另一方面,它有误导性,因为App Store上有许多相机应用程序,如Snapchat,它们明显使用音量按钮/长按用于其他目的。

无论如何,我设法处理长按,看到这个线程: https//github.com/jpsim/JPSVolumeButtonHandler/issues/27#issuecomment-253979943

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM