0
我正在開發一個應用程序,允許用UIPanGesture瀏覽視頻。反轉MPMoviePlayerController
我已經完全向前運行,這是我遇到的麻煩。
- (void) handlePanGesture:(UIPanGestureRecognizer*)pan{
if(pan.state == UIGestureRecognizerStateEnded)
{
moviePlayer.currentPlaybackRate = 0.00;
currentTranslate = 0;
}
else
{
CGPoint translate = [pan translationInView:self.view];
CGFloat xCoord = translate.x;
CGFloat diff = (xCoord - currentTranslate);
CGFloat currentRate = [moviePlayer currentPlaybackRate];
currentTranslate = xCoord;
if (diff>=0) {
//If the difference is positive
moviePlayer.currentPlaybackRate = currentRate + (diff/100);
} else {
//If the difference is negative
moviePlayer.currentPlaybackRate = (currentRate + (diff/100)) * -1.0;
}
NSLog(@"%F",moviePlayer.currentPlaybackRate);
}
}
基本上這樣做是檢測如果手勢狀態是「結束」,如果不是的話,即手勢繼續,計算以前的X座標和當前的x座標之間的差異。如果差值是正值(即從左到右移動),則通過計算播放速率來提前播放視頻。如果差值爲負值(向後),則取消差值並計算回放速率。
我似乎無法得到正確的向後運動。誰能幫忙?