簡體   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