Xcode:如何在webview中停止视频并仍然使用webview

时间:2013-10-01 11:11:44

标签: uiwebview uiscrollview ios7 uipagecontrol

如果我使用

 -(void)viewWillDisappear:(BOOL)animated
    {
        [subView loadHTMLString:nil baseURL:nil];
    }

我的Webview无法正常工作

I try to do this
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    pageControlBeingUsed = NO;

    [subView loadHTMLString:nil baseURL:nil];


}

我只想在下一页上使用分页滚动视图并在下一页停止视频

这是我的代码scrollview分页

book = [[NSMutableArray alloc] initWithObjects:@"page11",@"page12",@"page13",@"page14",@"page15", nil];

for (int i = 0; i < [book count]; i++) {

    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.height * i;
    frame.origin.y = 0;
    frame.size = CGSizeMake(1024,768);
    subView = [[UIWebView alloc] initWithFrame:frame];
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:i] ofType:@"html" inDirectory:@""]];
    [subView loadRequest:[NSURLRequest requestWithURL:url]];
    subView.scalesPageToFit = YES;
     [scrollView setBounces:NO];
    [scrollView addSubview:subView];
}
scrollView.contentSize = CGSizeMake(1024 * [book count], 768);
[scrollView setFrame:CGRectMake(0, 0, 1024, 768)];

我可以播放视频并停留在下一页吗? //请咨询

抱歉,我的英语不太好

2 个答案:

答案 0 :(得分:0)

您需要将空白页面加载到UIWebView中以停止音频:

[self.webView loadRequest:NSURLRequestFromString(@"about:blank")];

[self.webView  loadHTMLString:@"" baseURL:nil];

答案 1 :(得分:0)

感谢建议。我试着这对我有用

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    pageControlBeingUsed = NO;
    CGFloat pageWidth = self.scrollView.frame.size.width;
    int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;


    for(int i = 0; i < _pageAmount ; i++){

        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
        [_collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor clearColor];
    }

    currentPage = page;

    if (currentPage > 0 && currentPage < [book count]-1) {
        [[self.scrollView.subviews objectAtIndex:currentPage-1]reload];//
        [[self.scrollView.subviews objectAtIndex:currentPage+1]reload];

    }

    if(self.interfaceOrientation == 1 || self.interfaceOrientation == 2){

        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:page inSection:0];
        [_collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor redColor];

    }
}