gpt4 book ai didi

iphone - WebView :shouldStartLoadWithRequest:navigationType: not getting called on webkit with youtube video link iphone

转载 作者:行者123 更新时间:2023-12-03 19:23:04 26 4
gpt4 key购买 nike

我正在使用 webkit 在 iOS4 上显示 YouTube 视频。单击视频后,它应该自动启动播放器并显示视频,但实际情况是视频在播放器中渲染,但在 WebView 下。我想做的是使 webview 的 alpha 为 0 所以我使用委托(delegate)

      webView:shouldStartLoadWithRequest:navigationType:

但是当点击视频来启动它时,该代表不会被调用。否则,当第一个 webview 本身从 url 启动时,它就会被调用。

编辑

- (void)loadView {
[super loadView];

activityIndicatorView = [[ActivityIndicator alloc] init];

web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate = self;
NSString *videoUrl = @"http://www.youtube.com/watch?v=";
NSString *fullVdoUrl = [videoUrl stringByAppendingFormat:_videoUrl];

NSString *urlAddress = [NSString stringWithFormat:fullVdoUrl];
NSURL *url = [NSURL URLWithString:urlAddress]; //Create a URL object.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //URL Requst Object
[web loadRequest:requestObj]; //Load the request

[self.view addSubview:web];
[web release];

}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicatorView.view removeFromSuperview];
web.alpha = 1.0;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
[self.view addSubview:activityIndicatorView.view];
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
web.alpha = 0.0;
return YES;
}

最佳答案

- (void)loadView {
[super loadView];

activityIndicatorView = [[ActivityIndicator alloc] init];

web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate = self;
NSString *videoUrl = @"http://www.youtube.com/watch?v=";
NSString *fullVdoUrl = [videoUrl stringByAppendingFormat:_videoUrl];

NSString *urlAddress = [NSString stringWithFormat:fullVdoUrl];
NSURL *url = [NSURL URLWithString:urlAddress]; //Create a URL object.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //URL Requst Object
[web loadRequest:requestObj]; //Load the request

[self.view addSubview:web];
[web release];

}

这里:

[self.view addSubview:web];

self.view 为 nil,将 view 添加到 nil 将不会保留您的 webview。

[网络发布];

您正在释放保留计数为 0 的 WebView。

尝试

self.view = web;
[web release];

这对你有用。

关于iphone - WebView :shouldStartLoadWithRequest:navigationType: not getting called on webkit with youtube video link iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3777530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com