2011-02-06 106 views
6

我正在使用AVPlayer複製MPMediaPlayerView,因此我可以爲其添加一些功能。我創建了一個帶有播放/暫停的UIView,並將其顯示在觸摸上,然後設置一個計時器以按照HeadsUpUI示例代碼隱藏它。我已經添加了一個MPVolumeView來調整音量。在MPVolumeView中檢測觸摸

工作正常,除了如果你滑動的音量左右,我的父視圖不知道你還在與子視圖交互並在計時器觸發時隱藏自身。所以你仍然在調整音量,但滑塊不再存在。

我最想知道的是當觸摸在視圖和所有子視圖上結束時。有沒有辦法做到這一點?

我能想到的唯一解決方案是走MPVolumeView的子視圖,當我找到滑塊時,觀察跟蹤屬性以瞭解它何時完成跟蹤。但是,這並不能解決長時間按住按鈕的問題。我真的很想找到一個通用的解決方案。

TIA

回答

7

將手勢識別器添加到MPVolumeView中。讓手勢識別器調用視圖中重置計時器的方法。

MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(0, 88, 320, 30)]; 
UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(volumeAdjusted:)]; 
recognizer.cancelsTouchesInView = NO;  // this line is VERY important 
[volumeView addGestureRecognizer:recognizer]; 
[self.view addSubview:volumeView]; 
[volumeView release]; 

-(void)volumeAdjusted:(UIGestureRecognizer *)recognizer { 
    // reset timer 
} 
+0

對於前3.2的情況如何?擴展MPVolumeView並實現觸摸*事件似乎不起作用。有什麼想法嗎? – Ephraim 2012-05-23 21:10:19