我正在开发和应用程序,我想在页面中的YouTube视频。 它适用于以下代码:
-(void)viewDidLoad{
[super viewDidLoad];
}
- (void) viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.47 green:.43 blue:.4 alpha:1];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
NSString *htmlString;
if(interfaceOrientation == UIInterfaceOrientationPortrait){
htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 20\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"768\" height=\"960\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"768\" height=\"960\"></embed></object></div></body></html>",urlToOpen,urlToOpen];
}else{
htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"1024\" height=\"704\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"1024\" height=\"704\"></embed></object></div></body></html>",urlToOpen,urlToOpen];
}
[self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
return YES;
}
视图在纵向和横向上都能正常工作。 问题是当我看到带有完整屏幕和i旋转的视频时。当我完成整个屏幕时,webview没有检测到旋转并以错误的方式打印webview。
如何检测Youtube全屏旋转以旋转我的视图?
三江源
答案 0 :(得分:0)
将内容宽度设置为100%
我的模板
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \
<html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> \
<meta name=\"viewport\" content=\"width=320\"> \
<style> \
html,body {-webkit-text-size-adjust: none; size:100%%} \
body {margin: 0; padding: 0;width:100%;} \
table { font-family:Georgia; font-size:%dpt; border-style: none; size:100%%} \
</style> </head>
...
答案 1 :(得分:-1)
我假设您已经处理了方向回调? (shouldAutorotateToInterfaceOrientation,didRotateFromInterfaceOrientation)
当YouTube视频完成并将焦点返回到您的应用时,应调用viewWillAppear方法。在那里,您可以获得设备方向:
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
然后执行布局更改。这也会在首次打开此视图时处理布局。
您可以在switch语句中执行此操作:
switch(orientation) {
case UIInterfaceOrientationLandscapeLeft: //layout for this landscape mode
case UIInterfaceOrientationPortraitUpsideDown: //layout for this portrait mode
答案 2 :(得分:-1)
我使用像这样的NSNotification来处理这个问题
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerDidExitFullScreen)
name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
object:nil];
和将要调用的方法是
- (void)moviePlayerDidExitFullScreen
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
}
希望能帮助