0

嗨,我有一个 youtube 网址,我将其加载到 html 嵌入的 webview 中。一切正常。视频以 potrait 模式播放。问题是当我将设备旋转到横向,而视频以 potrait 播放时,视频没有以横向模式播放。因为我将视频嵌入到 html webview 中。你能伙计们帮我解决这个问题。

   - (void)embedYouTube:(NSString*)url frame:(CGRect)frame {
        NSString* embedHTML = @"\
        <html><head>\
        <style type=\"text/css\">\
        body {\
            background-color: transparent;\
        color: white;\
        }\
        </style>\
        </head><body style=\"margin:0\">\
        <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
        width=\"%0.0f\" height=\"%0.0f\"></embed>\
        </body></html>";
        NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
        if(webView == nil) {
            webView = [[UIWebView alloc] initWithFrame:frame];

        }
        [webView loadHTMLString:html baseURL:nil];
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self embedYouTube:urlString frame:CGRectMake(0, 0, 320, 568)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification object:nil];

    }


- (void)viewWillAppear:(BOOL)animated {
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation))
    {
        //I set my new frame origin and size here for this orientation
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait)
    {
        //I set my new frame origin and size here for this orientation
        isShowingLandscapeView = NO;
    }
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
    {
        //I set my new frame origin and size here for this orientation
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
    {
        //I set my new frame origin and size here for this orientation
        isShowingLandscapeView = NO;
    }
}

- (void)orientationChanged:(NSNotification *)notification
{
    // We must add a delay here, otherwise we'll swap in the new view
    // too quickly and we'll get an animation glitch
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}




- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || UIInterfaceOrientationIsLandscape(interfaceOrientation));
}

-(IBAction)onHome{
[self dismissModalViewControllerAnimated:YES];
}
4

0 回答 0