【发布时间】:2014-01-03 07:23:48
【问题描述】:
我在服务器上有视频,我正在使用 webview 播放视频,但是当我第一次点击完成时(在 webview 中)它会上升,而第二次它工作正常请建议我如何解决这个问题...
-(void)showPopViewWithUrl:(NSString*)url {
self.navigationController.navigationBar.hidden = YES;
float diff = [UIScreen mainScreen].bounds.size.height - self.view.frame.size.height;
UIView* popView = [[UIView alloc] init];
popView.frame = CGRectMake(0, -diff, self.view.frame.size.width, self.view.frame.size.height+diff);
[popView setBackgroundColor:[UIColor yellowColor]];
UIWebView* webview = [[UIWebView alloc] init];
webview.backgroundColor = [UIColor clearColor];
[webview setFrame:CGRectMake(0, 0, 300, 250)];
UIButton* crossBtn = [UIButton buttonWithType:UIButtonTypeCustom];
crossBtn.backgroundColor = [UIColor clearColor];
[crossBtn addTarget:self action:@selector(crossBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[crossBtn setImage:[UIImage imageNamed:@"close_pop.png"] forState:UIControlStateNormal];
[crossBtn setFrame:CGRectMake(popView.frame.size.width-30, popView.frame.size.height-40, 30, 30)];
[popView addSubview:webview];
[webview addSubview:crossBtn];
[self.view addSubview:popView];
[self playVideo:url webview:webview];
}
- (void)playVideo:(NSString *)urlString webview:(UIWebView*)videoView {
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
<script>\
function load(){document.getElementById(\"yt\").play();}\
</script>\
</head><body onload=\"load()\"style=\"margin:0\">\
<video id=\"yt\" src=\"%@\" \
width=\"%0.0f\" height=\"%0.0f\" autoplay controls></video>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString,videoView.frame.size.width, videoView.frame.size.height];
[videoView loadHTMLString:html baseURL:nil];
// [self.view addSubview:videoView];
NSLog(@"%@",html);
}
【问题讨论】:
标签: ios objective-c cocoa webview