2011-11-14 57 views
2

我正在开发和应用程序,我希望在一个页面的YouTube视频。 它工作正常枝条下面的代码:ios,在webview中的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; 
} 

工作在纵向和横向细的观点。 问题是,当我看到全屏和我旋转的视频。当我完成整个屏幕时,webview没有检测到旋转并以错误的方式打印webview。

我怎么能检测到Youtube全屏旋转旋转我的看法?

Thankyou

回答

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

我假设你已经在处理方向回调? (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 
+0

Thnks但它也不是真正正确的。 youtube全屏幕是当用户推动使得视频像屏幕一样大的两个箭头时。然后,当您使用此全屏旋转并按下“完成”时,屏幕会保持原始方向。 viewWillAppear不被调用。 – ValentiGoClimb

-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]; 
    } 
} 

希望帮助

+0

私有API使用可能会破坏您的应用程序或导致拒绝。 – iSaalis

+0

私有API?你能看到上面的私有api用法吗? –

+0

UIMoviePlayerControllerDidExitFullscreenNotification没有记录在任何地方。所以,它可以在操作系统更新中进行更改......另外,使用未公开的通知可能会导致拒绝。 – iSaalis