UIWebView和UIScrollView上接受touch事件
来源:互联网 发布:nginx反向代理apache 编辑:程序博客网 时间:2024/06/03 09:33
- (void)viewDidLoad{
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
self.webView.delegate=self;
NSString *resourcePath = [ [NSBundle mainBundle] resourcePath];
NSString *filePath = [resourcePath stringByAppendingPathComponent:@"test.html"];
NSString *htmlstring=[[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSString *newHTMLString=[htmlstring stringByAppendingString:@"<scriptlanguage=/"javascript/">document.ontouchstart=function(){ document.location=/"myweb:touch:start/"; }; document.ontouchend=function(){ document.location=/"myweb:touch:end/"; }; document.ontouchmove=function(){ document.location=/"myweb:touch:move/"; } </script>"];
[self.webView loadHTMLString:newHTMLString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
[htmlstring release];
webView.backgroundColor = [UIColor redColor];
webView.frame = CGRectMake(0, 0, 768, 1024);
[self.view addSubview:webView];
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if ([components count] > 1 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"myweb"]) {
if([(NSString *)[components objectAtIndex:1] isEqualToString:@"touch"])
{
NSLog(@"%@",[components objectAtIndex:2]);
}
return NO;
}
return YES;
}
UIScrollView上touch事件的捕捉:
创建一个继承于UIScrollView的类,
@interface MyScrollView : UIScrollView {
}
@end
并改写其touch方法;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if(!self.dragging)
{
[[self nextResponder] touchesBegan:touches withEvent:event];
}
[super touchesBegan:touches withEvent:event];
//NSLog(@"MyScrollView touch Began");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(!self.dragging)
{
[[self nextResponder] touchesEnded:touches withEvent:event];
}
[super touchesEnded:touches withEvent:event];
}
- UIWebView和UIScrollView上接受touch事件
- UIWebView和UIScrollView上接受touch事件
- UIWebView和UIScrollView上接受touch事件
- 细说UIScrollView上的Touch 事件
- 细说UIScrollView上的Touch 事件
- 细说UIScrollView上的Touch 事件
- 细说UIScrollView上的Touch 事件
- UIScrollView上的控件处理touch事件
- 细说UIScrollView上的Touch 事件
- UIScrollView touch 触摸事件
- UIWebView上Touch/UITapGestureRecognizer事件的最简单的方法
- 获取UIWebView的touch事件
- UIScrollView的touch事件特点
- cocos2dx CCLayer接受 touch 事件
- iPhone开发--检查UIWebView上Touch/UITapGestureRecognizer事件的最简单的方法(转载)
- 如何使UIWebView响应Touch事件
- UIScrollView无法响应touch事件的解决办法
- UIScrollView无法响应touch事件的解决办法
- RHEL6中创建ISO镜像文件
- JPQL
- cocos2d_x+lua【3】 ——label的使用
- 修改Latex常用编辑器WinEdt中的字号与字体
- IDBLK_TIMING.dll群联量产数据库文件合集
- UIWebView和UIScrollView上接受touch事件
- java.lang.NoSuchMethodError
- (百例编程)87.黑白子交换
- UIWebView和UIScrollView上接受touch事件
- c#如何将txt文本内容进行清空(C#清空txt文本内容)
- 计算机操作系统存储管理(分段与分页)
- 设计模式读书笔记-----工厂方法模式
- HDU4515(日期的前后推算)
- 将16进制的颜色值变成UIColor