如何在横向模式下在webview中制作html嵌入视频

时间:2013-06-03 07:06:51

标签: objective-c uiwebview

您好我有一个youtube网址,我在html嵌入式webview中加载它。一切都工作得很好。视频在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];
}

0 个答案:

没有答案