我正在创建UIScrollView
并添加四个UIWebViews
作为子视图。
我想做两件事:
WebView
时对其进行标记,以便稍后在UIScrollView
内对其进行处理。scrollViewWillBeginDragging
)将JavaScript发送到UIWebView
当前显示的UIScrollview
。我不知道如何标记子视图以及如何解决它。所以我的两个问题是:
Q1。如何正确标记子视图(将其添加到UISCrollView中)?
Q2。如何在UIScrollView中处理子视图的命令? ((最好的情况:当前显示的那个))
感谢您的帮助!
通过查看实际代码可能会澄清问题:
以下是我用来创建UIWebviews
并将其添加到UIScrollview
(scrollView1)的代码:
- (void)viewDidLoad{
scrollView1.delegate = self;
scrollView1.pagingEnabled = YES;
scrollView1.delaysContentTouches = NO;
NSInteger numberOfViews = 4;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
UIWebView *WebView1 = [[UIWebView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"page_%d", i] ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[WebView1 loadRequest:request];
//HERE I'M TRYING TO TAG THE VIEW
WebView1.tag = i;
[scrollView1 addSubview:awesomeView];
[WebView1 release];
}
scrollView1.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
以下是我想用来解决UIWebviews
(scrollView1)中UIScrollview
的代码:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView1{
NSString *JavaScriptCommand = [NSString stringWithFormat:@"player.pause();"];
<strong>//HERE I'M TRYING TO ACCESS THE TAGGED VIEW</strong>
[scrollView1.????? stringByEvaluatingJavaScriptFromString:JavaScriptCommand];
}
答案 0 :(得分:0)
这应该有效
int i = // the tag of the webview you want to address
[[scrollView1 viewWithTag:i] stringByEvaluatingJavaScriptFromString:JavaScriptCommand];
您可以存储当前在视图控制器类成员中显示的UIWebView标记。