2013-07-01 64 views
1

我很難試圖用UIProgressView替代UISlider在我的應用程序中播放不可見的MPMoviePlayerController如何用UIProgressView替換UISlider播放MPMoviePlayerController?

UISlider剛剛創建,很直觀的改變,差不多上的更新選擇從MPMoviePlayerController我更新其當前狀態:

:我從 MPMoviePlayerController的內容定義的最小和最大

和以前

-(void)UpdateTime:(NSTimer*)Timer 
{ 

[self.sldProgress1 setValue:[[NSNumber numberWithDouble:playerSong.currentPlaybackTime] floatValue]]; 

} 

UIProgressView沒有提供類似的做法,我並沒有在網絡上找到的樣品符合我想做的事:

 sldProgress2.maximumValue = [playerSong playableDuration]; 
     sldProgress1.value = 0.0; 

有什麼建議嗎?

+0

怎麼樣self.sldProgress1.progress = playerSong.currentPlaybackTime; – Swissdude

回答

1

UIProgressView沒有用戶可設置的最大值的概念 - 它只是100.0。爲了讓它按照你的想法工作,你必須做一些數學。幸運的是,它很容易的數學:

CGFloat percentComplete = [playerSong.currentPlaybackTime floatValue]/[playerSong.playableDuration floatValue]; 

這會給你這是完整的歌曲的百分比,您只需更新您的UIProgressView到該號碼。

progressView.progress = percentComplete; 

或多或少 - 這段代碼大多是基於您的問題的僞代碼,但這就是我的想法。

+1

簡單而美麗 – RollRoll

0

您可以使用此行繼續使用UISlider和隱藏thumbImage:

[mySlider setThumbImage:[[UIImage alloc] init] forState:UIControlStateNormal]; 

這爲我工作。

相關問題