Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在YouTube视频框内显示活动指示器?_Iphone_Ios_Xcode_Youtube - Fatal编程技术网

Iphone 如何在YouTube视频框内显示活动指示器?

Iphone 如何在YouTube视频框内显示活动指示器?,iphone,ios,xcode,youtube,Iphone,Ios,Xcode,Youtube,在我的应用程序中,我正在使用以下代码嵌入YouTube视频: - (void)playVideo:(NSString *)urlString frame: (CGRect)frame { NSString *embedHTML = @"<body style=\"margin:0\"> <iframe height=\"110\" width=\"110\" src=\"http://www.youtube.com/embed/video id\" frameborder=

在我的应用程序中,我正在使用以下代码嵌入YouTube视频:

- (void)playVideo:(NSString *)urlString frame:  (CGRect)frame
{

NSString *embedHTML = @"<body style=\"margin:0\"> <iframe height=\"110\" width=\"110\" src=\"http://www.youtube.com/embed/video id\" frameborder=\"0\"/></iframe> </body> ";


NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];


[videoView loadHTMLString:html baseURL:nil];
[self.scrollView addSubview:videoView];
[videoView release];
NSLog(@"%@",html);

}
但是当我的视图加载时,需要一段时间才能显示我的视频,这可能会让用户感觉什么都没有发生,所以我想在这些帧中显示一个活动指示器。 你们能帮我吗?谢谢。

查看您如何将“
videoView
”添加到滚动视图中?为什么不以类似的方式将“
UIActivityIndicator
”视图作为子视图添加到视频视图或滚动视图中


确保保留活动指示器的手柄/插座,并在视频开始播放时将其卸下。

要使用
UIWebview
更好的性能,请使用这种方式

ViewController.h
文件中

– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidStartLoad:
– webViewDidFinishLoad:
– webView:didFailLoadWithError:
第一组
UIWebViewDelegate
作为代理

@interface ViewController : UIViewController<UIWebViewDelegate> {

        UIWebView *videoView;
}
编写代码显示相应的活动指示器代码显示指示器

有关更多详细信息,请参阅

编辑:

  • –webViewDidStartLoad:
    方法中显示并启动Activityindicator的动画

  • –webViewDidFinishLoad:
    方法中停止Activityindicator的动画

  • 别忘了设置
    委托


  • 我尝试过你的if语句,但是我不确定在if后面的两个括号()中放什么代码。你能给我一个代码来帮助我吗。谢谢。我没有看到您的问题中当前显示的代码中的“
    if
    ”语句。你能编辑你的问题来显示你在实现(源代码)中谈论的是什么吗?这是我实际上想做的,我指的是if语句,但我没有实际添加它,因为正如我所说的,我不确定我需要在两个括号中放什么代码。但是我可以告诉你我想做什么:如果webView没有加载,显示活动指示器,否则隐藏活动指示器。像这样的。
    – webView:shouldStartLoadWithRequest:navigationType:
    – webViewDidStartLoad:
    – webViewDidFinishLoad:
    – webView:didFailLoadWithError: