【问题标题】:How to use Multiple Webviews in bottom of ViewController?如何在 ViewController 底部使用多个 Webview?
【发布时间】:2012-07-18 22:51:51
【问题描述】:

我在服务器上已经有 10 个 youtube 视频链接。每个 youtube 视频都应该是 webview 中的缩略图。在给定的图像中,(红框)显示空间较小,用于在 webview 中显示所有 youtube 缩略图,所以我们如何滚动( redbox)viewcontroll 区域以及如何在运行时为(redbox)区域中从上到下的每个 youtube 链接创建 webview。任何建议或帮助将提前获得。thanx

【问题讨论】:

  • 您只需要显示缩略图,对吗?不需要在那里玩吗?
  • 是的,我这里只需要缩略图,但是当我们点击任何缩略图时,它会转到另一个视图以在全屏视图的 web 视图中播放。

标签: iphone xcode uiwebview uiscrollview youtube


【解决方案1】:

为了实现这一点,您可以使用scrollviewwebview

首先在视图中添加一个滚动视图(在红色矩形的位置)

UIScrollView *scrollView = [[UIScrollView  alloc] initWithFrame:CGRectMake(0,0,150,150)]; //You need to set the frame according to your need.
scrollView.contentSize = CGSizeMake(150,600);
scrollView.userInteractionEnabled = YES;
[self.view addSubview:scrollView];
[self.view bringSubviewToFront:scrollView];

现在向该滚动视图添加十个网络视图

int yPos = 0;
for(int loop = 0; loop<10;loop++)
{
  UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,yPos,50,50)]
  NSString *htmlString = @"<html><head>
<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head>
<body style=\"background:#F00;margin-top:0px;margin-left:0px\">
<div><object width=\"212\" height=\"172\">
<param name=\"movie\" value=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param>
<param name=\"wmode\" value=\"transparent\"></param>
<embed src=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"
type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"212\" height=\"172\"></embed>
</object></div></body></html>";

  //if your video url's are stored in an array then
  NSString *str = (NSString *)[urlArray objectAtIndex:loop];
  [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@str]];
  [scrollView addSubview:webView];
  [webView release];
  webView = nil;
  yPos += 70;
}


[scrollView release];

这将在您的页脚视图中添加 10 个小型 you Tube 嵌入式播放器。您可以滚动页脚以查看视频的缩略图。

注意:您需要根据您的视图更改框架和内容大小。

【讨论】:

  • 这会给你一个上下滚动,而不是左右滚动。如果需要,请更改 contentSize 的宽度属性。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-11
  • 1970-01-01
  • 2019-01-25
  • 2023-04-10
  • 2021-07-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多