ios - 表格单元格横向模式下的 Youtube 播放器

标签 ios objective-c uitableview uiwebview youtube

我有一个只支持纵向模式的应用程序,它有一个表格,每个单元格包含一个标题和一个带有 YouTube 视频的 web View 。

现在您将如何让 Youtube 播放器同时处于横向和纵向模式?

    [cell.titleLabel setText:[[[StoreVars sharedInstance].sharedArrayOfVideo objectAtIndex:indexPath.row] objectForKey:@"title"]];
    NSString *ID = [[[StoreVars sharedInstance].sharedArrayOfVideo objectAtIndex:indexPath.row] objectForKey:@"id"];
    NSString *code = [NSString stringWithFormat:@"<iframe width=\"280\" height=\"170\" src=\"//www.youtube.com/embed/%@\" frameborder=\"0\" allowfullscreen></iframe>",ID];
    NSLog(@"Loading video: %@",code);
    [cell.videoWebView loadHTMLString:code baseURL:[NSURL URLWithString:@"http:"]];
    [cell.videoWebView.scrollView setScrollEnabled:NO];
    [cell.videoWebView.scrollView setBounces:NO];

我四处搜索并找到了这样的代码,但我无法访问单元格 webview。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(webView && webView.superView) return YES;
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

最佳答案

如果您正在为 iOS 6.0 及更高版本进行开发,我建议您使用
-supportedInterfaceOrientations

但是,我不建议使用这种方法来旋转单元格,因为我很确定它不会在设备改变其方向时一直被调用(特别是如果父 Controller 已经禁用横向)。你可以试试听UIDeviceOrientationDidChangeNotification在您的(子类)单元格中旋转 webview 并在您的 View Controller 中(使用表格 View )并在您的表格 View 上运行 -reloadData 以正确调整单元格的大小(假设横向 webview 比纵向 webview 高得多)

关于ios - 表格单元格横向模式下的 Youtube 播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18351866/

相关文章:

iOS 本地化问题

ios - 二元运算符 + 不能应用于 CGfloat int 类型的操作数

ios - Storyboard 状态栏后面的内容

objective-c - 使用 iOS Dropbox SDK 分块上传核心数据

ios - 引用具有重用标识符的单元格

objective-c - 如何修复缓慢滚动的表格 View

iphone - 快速 TableView 滚动和后退按钮点击

ios - 自动辞职并在 Swift 的文本字段中分配第一响应者

ios - 如何使 [load on scroll] 不继续将图像添加到 ram?

ios - 通知没有到达我的 iOS 应用程序