Ios YTPlayerView-对YTPlayerView的自动旋转支持
我正在使用Ios YTPlayerView-对YTPlayerView的自动旋转支持,ios,objective-c,uiwebview,ytplayerview,Ios,Objective C,Uiwebview,Ytplayerview,我正在使用YTPlayerView类来播放YouTube视频。下面是我根据设备屏幕大小(iPad大屏幕,iPhone小屏幕)加载视频的代码。它工作得很好 问题-- 当我将设备模式更改为横向模式时,我希望在纵向模式下使用更大的YTPlayerView。目前,两种屏幕模式下的视频大小相同 - (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams { NSDictionary *playerCallbacks = @{
YTPlayerView
类来播放YouTube
视频。下面是我根据设备屏幕大小(iPad大屏幕,iPhone小屏幕)加载视频的代码。它工作得很好
问题--
当我将设备模式更改为横向模式时,我希望在纵向模式下使用更大的YTPlayerView
。目前,两种屏幕模式下的视频大小相同
- (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams {
NSDictionary *playerCallbacks = @{
@"onReady" : @"onReady",
@"onStateChange" : @"onStateChange",
@"onPlaybackQualityChange" : @"onPlaybackQualityChange",
@"onError" : @"onPlayerError"
};
NSMutableDictionary *playerParams = [[NSMutableDictionary alloc] init];
[playerParams addEntriesFromDictionary:additionalPlayerParams];
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
[playerParams setValue:@"551px" forKey:@"height"];
[playerParams setValue:@"768px" forKey:@"width"];
}
else
{
[playerParams setValue:@"250px" forKey:@"height"];
[playerParams setValue:@"320px" forKey:@"width"];
}
-----
-----
}
我不能使用此检查来提供更大尺寸的视图,因为上面的代码在视频播放之间没有调用
if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscape)
你们知道如何解决这个问题吗?或者,如果有任何其他解决方案使用JavaScript和css作为webView的html字符串。YTPlayerView实际上使用webView来播放viedo,因此您只能使用css或JavaScript来更改大小。资产文件夹中应该有一个名为“YTPlayerView iframe player.html”的html文件 以下是css示例:
<style>
body { margin: 0; width:100%%; height:100%%; }
html { width:100%%; height:100%%; }
</style>
正文{边距:0;宽度:100%%;高度:100%%;}
html{宽度:100%%;高度:100%%;}
我在我的故事板中使用了YTPlayer,并且在我的项目中使用自动布局时,在上面添加了适当的约束。它在横向和纵向模式下对我来说都很好。。我认为解决你问题的办法是自动布局