我有一个 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/