UIWebView和UIScrollView上接受touch事件
来源:互联网 发布:spss22如何保存数据 编辑:程序博客网 时间:2024/06/07 10:30
UIWebView 的touch事件的捕捉:
- (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:@"<script language=/"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事件的解决办法
- VS2008中安装WTL
- ms sql 时间函数
- Linux下SVN配置
- FF IE 盒子模型
- Linux下计划任务cron使用方法
- UIWebView和UIScrollView上接受touch事件
- 求助!!请高手们帮忙把下面的这段C代码改写成相应的C#代码!谢谢!!
- phpMyAdmin 登陆超时(1440秒未活动),请重新登录问题
- ABAP基础知识学习(一)
- Java MyEclipse 快捷键
- hdu3546 Calculator
- ABAP基础知识学习(二)
- 如何成为一名优秀的程序员
- XDS510与XDS560的区别