1
使用Youtube iOS幫助程序庫在我的應用程序中內聯播放YT視頻。我的應用程序一般工作順利,視頻加載和播放良好。我有一個問題,當我旋轉手機(模擬器)時,視頻會離開框架。因此,如果我以縱向方式加載視頻,視頻將以肖像爲中心,但當我旋轉到風景時,視頻將位於底部角落。UIWebView嵌入式Youtube視頻不平滑旋轉
爲了解決這個問題,我現在用一些javascript調整播放器大小。
- (void)setSizeOfIFrameToWidth:(int)width Height:(int)height {
[self.webView stringByEvaluatingJavaScriptFromString:
[NSString stringWithFormat:@"player.setSize(%d, %d)", width, height]];
}
(那是在我編輯的YTPlayer類中)。
這工作得很好,並得到堪稱youtubeView的主人:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.youtubeView setSizeOfIFrameToWidth:self.youtubeView.frame.size.width Height:self.youtubeView.frame.size.height];
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[self.youtubeView setNeedsDisplay];
}
(我不知道如果這最後setNeedsDisplay
線沒有做任何事情)
但是現在,當它旋轉時,首先查看在側面被切斷,然後轉動笨拙。它看起來非常波濤洶涌。這裏是最好的截圖,我可以得到:
而且還
注意如何旋轉過程中的視頻被削減。
(根據記錄,我沒有自己的權利,在播放器中的視頻。這就是從這裏https://www.youtube.com/watch?v=Q78COTwT7nE)