iphone - 自动旋转从 UIWebView 播放的视频到横向模式

标签 iphone objective-c uiwebview

我有一个 UIWebView,这样填充:

[myWebView loadHTMLString:@"<iframe src=\"http://www.youtube.com/embed/grTCDFbhKMU\" frameborder=\"0\" allowfullscreen></iframe>"
baseURL:nil];

视频已正确启动,但无法切换到横向模式。

我已经在相关的 ViewController 中写了这个:

- (void)didRotate:(NSNotification *)notification
{
    UIDeviceOrientation orientation = [[notification object] orientation];

    if (orientation == UIDeviceOrientationLandscapeLeft)
    {
        [self.newsContent setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
    }
    else if (orientation == UIDeviceOrientationLandscapeRight)
    {
        [self.newsContent setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
    }
    else if (orientation == UIDeviceOrientationPortraitUpsideDown)
    {
        [self.newsContent setTransform:CGAffineTransformMakeRotation(M_PI)];
    }
    else if (orientation == UIDeviceOrientationPortrait)
    {
        [self.newsContent setTransform:CGAffineTransformMakeRotation(0.0)];
    }
}

对于改变内容方向很有用,但一旦视频启动就没用了:(

有什么想法吗?

最佳答案

您应该在以下方法中返回 YES:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    //All orientations are accepted except for the upsidedown orientation
    if(interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown) {
        return YES;
    } else {
        return NO;
    }
}

如果返回YES则旋转,如果返回no则不旋转。

关于iphone - 自动旋转从 UIWebView 播放的视频到横向模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6426941/

相关文章:

iphone - 按 ID 加载单个视频的 YouTube GData 提要

ios - 在 WebVIew 中加载请求时应用程序崩溃 - Objective C

iphone - Objective C 封装

objective-c - 在自定义 NSView 放置事件的每个实例的基础上执行某些操作

ios - 更改 UIWebView 上的 cookie 策略

iphone - UIWebView NSURLRequestReloadIgnoringLocalCacheData 实际上并没有忽略缓存

iphone - 将 GDB 附加到进程 ID 并在 iPhone 上列出其 ARM 寄存器的最佳方法?

iPhone 问题 : How can I add a button to a tableview cell?

iphone - ResignFirstResponder 不会关闭键盘 (iPhone)

iphone - 用于签署 iPhone 应用程序的配置文件名称?