- 浏览: 1041784 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (675)
- ios (214)
- android-course (5)
- unity3d (7)
- cocos2d (36)
- html5 (3)
- game (5)
- android (42)
- java (57)
- php (12)
- 创业 (10)
- SEO (3)
- 架构 (2)
- 数据库 (3)
- 产品设计 (9)
- 操作系统 (10)
- Web前端 (11)
- 其他 (50)
- GAE (1)
- mac os (8)
- Open Source (2)
- 序列号 (10)
- C (2)
- database (2)
- 算法 (6)
- 设计模式 (1)
- photoshop (1)
- 3dmax (1)
- maya (1)
- opengl (3)
- 游戏设计 (1)
- 趋势 (1)
- cocos2d-x (4)
- shell (3)
- c++ (30)
- lua (5)
- flash (1)
- spring (3)
- mysql (4)
- Git (6)
- xmpp (1)
- cocos2dx (14)
- mac (2)
- 编程规范 (2)
- windows (1)
- linux (5)
- coocs2dx (1)
- ubuntu (2)
- aws (1)
- OPENGLES (1)
- 原画 (1)
最新评论
-
jlees:
Best mobile app testing tool pc ...
iOS + XCode 4 + GHUnit = Mobile TDD+Continuous testing -
ipanda:
楼主,能否给一个Micro CloudFoundry的虚机或者 ...
Cloud Foundry使用及开发向导 -
love_zongming:
谢谢分享。。
visio2007序列号 -
雨花台舞水:
你这才是枪文把
套在 360 黑匣子外面的黑盒子:你被技术型枪稿吓到了么? -
hugh.wang:
改天试试
Mac版魔兽争霸3 1.24e下载
Recently, I was working on a project which required detection of tap and events on the UIWebView. We wanted to find out the HTML element on which the user taps in the UIWebView and then depending on the element tapped some action was to be performed. After some Googling, I found out the most of the users lay a transparent UIView on top of the UIWebView, re-implement the touch methods of UIResponder class (Ex: -touchesBegan:withEvent:) and then pass the events to the UIWebView. This method is explained in detail here. There are multiple problems with the method.
- Copy/Selection stops working on UIWebView
- We need to create a sub-class of UIWebView while Apple says we should not sub-class it.
- A lot other UIWebView features stop working.
We ultimately found out that the right way to implement this is by sub-classing UIWindow and re-implementing the -sendEvent: method. Here is how you can do it. First, create a UIWindow sub-class
#import <UIKit/UIKit.h> @protocol TapDetectingWindowDelegate - (void)userDidTapWebView:(id)tapPoint; @end @interface TapDetectingWindow : UIWindow { UIView *viewToObserve; id <TapDetectingWindowDelegate> controllerThatObserves; } @property (nonatomic, retain) UIView *viewToObserve; @property (nonatomic, assign) id <TapDetectingWindowDelegate> controllerThatObserves; @endNote that we have variables which tell us the UIView on which to detect the events and the controller that receives the event information. Now, implement this class in the following way
#import "TapDetectingWindow.h"
@implementation TapDetectingWindow @synthesize viewToObserve; @synthesize controllerThatObserves; - (id)initWithViewToObserver:(UIView *)view andDelegate:(id)delegate { if(self == [super init]) { self.viewToObserve = view; self.controllerThatObserves = delegate; } return self; } - (void)dealloc { [viewToObserve release]; [super dealloc]; } - (void)forwardTap:(id)touch { [controllerThatObserves userDidTapWebView:touch]; } - (void)sendEvent:(UIEvent *)event { [super sendEvent:event]; if (viewToObserve == nil || controllerThatObserves == nil) return; NSSet *touches = [event allTouches]; if (touches.count != 1) return; UITouch *touch = touches.anyObject; if (touch.phase != UITouchPhaseEnded) return; if ([touch.view isDescendantOfView:viewToObserve] == NO) return; CGPoint tapPoint = [touch locationInView:viewToObserve]; NSLog(@"TapPoint = %f, %f", tapPoint.x, tapPoint.y); NSArray *pointArray = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%f", tapPoint.x], [NSString stringWithFormat:@"%f", tapPoint.y], nil]; if (touch.tapCount == 1) { [self performSelector:@selector(forwardTap:) withObject:pointArray afterDelay:0.5]; } else if (touch.tapCount > 1) { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(forwardTap:) object:pointArray]; } } @end
Implement the sendEvent method in the above way, and then you can send back the information you want back to the controller. There are few things that one needs to keep in mind. Make sure in your MainWindow.xib file, the window is of type TapDetectingWindow and not UIWindow. Only then all the events will pass through the above re-implemented sendEvent method. Also, make sure you call [super sendEvent:event] first and then do whatever you want. Now, you can create your UIWebView in the controller class in the following way
@interface WebViewController : UIViewController<TapDetectingWindowDelegate> { IBOutlet UIWebView *mHtmlViewer; TapDetectingWindow *mWindow; } - (void)viewDidLoad { [super viewDidLoad]; mWindow = (TapDetectingWindow *)[[UIApplication sharedApplication].windows objectAtIndex:0]; mWindow.viewToObserve = mHtmlViewer; mWindow.controllerThatObserves = self; }
Remember you'll need to write the method userDidTapWebView in your controller class. This is the method that is called in order to send the event information to the controller class. In our case above we are sending the point in the UIWebView at which the user tapped. Hope this was useful. Please let me know your suggestions and feedback.
转自:http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/
发表评论
-
Mac上安装Protocol Buffers
2016-09-18 11:29 8451.下载文件 (http://code.google.com ... -
webview点击获取图片
2016-04-01 17:12 842UILongPressGestureRecognizer * ... -
hexo 自动部署脚步
2016-03-29 21:17 942echo "===============star ... -
自定义navigationItem.leftBarButtonItem后,系统默认的手势滑动失效解决方案
2016-03-01 18:01 1292自定义navigationItem.le ... -
UITextView autolayout 高度自适应
2016-02-15 23:26 1426UITextView *t = [[UITextView ... -
腾讯敏捷框架TAPD》研究
2015-11-19 20:47 1435这篇文档是研究心得 ... -
ios image 压缩
2015-11-06 12:09 854- (UIImage *)_scaleToSize:(UII ... -
iphone分辨率图解
2015-11-04 17:33 586iphone分辨率图解 -
IOS中获取各种文件的目录路径的方法
2015-09-24 12:10 660iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储 ... -
Customizing Navigation Bar and Status Bar in iOS 7
2015-08-17 20:23 1627Like many of you, I have been ... -
GCD 深入理解:第一部分
2015-07-24 14:49 778本文翻译自 http://www.raywenderlich ... -
Mac上的抓包工具Charles
2015-05-06 01:09 5323Mac上的抓包工具Charles 分类: IO ... -
如何移除发布版本中的NSLog输出
2015-05-04 20:27 760Phone开发中会经常使用NSLog将一些运行信息输出到终端 ... -
xcode4的环境变量,Build Settings参数,workspace及联编设置
2015-03-27 11:23 945一、xcode4中的环境变量 $(BUILT_PROD ... -
数字签名是什么?
2014-11-25 16:58 628http://www.ruanyifeng.com/blog/ ... -
让你的Xcode更加高效
2014-10-29 00:16 534http://www.tairan.com/archives/ ... -
我所经历的“余额宝”的那些故事
2014-06-08 01:05 782“余额宝”经过不到 ... -
代码手写UI,xib和StoryBoard间的博弈,以及Interface Builder的一些小技巧
2014-05-31 01:25 803最近接触了几个刚入门的iOS学习者,他们之中存在一个普遍 ... -
WWDC 2013 Session笔记 - iOS7中的多任务
2014-05-31 01:24 681这是我的WWDC2013系列笔记中的一篇,完整的笔记列表 ... -
APP被苹果App Store拒绝的79个原因(未完待续)
2014-05-09 10:49 1163作为iOS开发者,估计有很多都遇到过APP提交到App Sto ...
相关推荐
2. UIWebViewDelegate:设置UIWebView的代理,可以监听到JavaScript的某些事件,比如`shouldStartLoadWithRequest`方法,可以捕获到JavaScript发起的URL请求。 三、JavaScript与Objective-C/Cocoa Touch交互 1. ...
在iOS应用开发中,UIWebView是一个...Xcode是苹果官方提供的开发工具,支持Objective-C和Swift编程语言,包含了Cocoa Touch框架,用于构建iOS应用。通过Xcode,开发者可以轻松创建全屏内置浏览器,并实现上述各种功能。
- `EventHandler`负责实际的事件处理逻辑,包括触发事件、传递事件等。 #### 第23篇 iOS的QuickTime Plugin - **QuickTime Plugin概述**: - QuickTime Plugin是iOS中用于播放多媒体内容的一个插件。 - 本文...
1. **Cocoa Touch框架**:掌握如何使用UIKit来创建视图和控制器,以及如何实现触摸事件处理和动画效果。 2. **WKWebView的使用**:了解如何配置和使用WKWebView来显示网页,处理JavaScript交互,以及如何设置安全...
3. **事件处理**:熟悉NSNotificationCenter和代理模式,确保事件正确传递。 4. **视图层次**:掌握如何有效管理视图层级,减少不必要的渲染和更新。 5. **KVC和KVO**:学习何时及如何使用,避免副作用和意外修改。 ...
这个压缩包文件"(0049)-iOS/iPhone/iPAD/iPod源代码-网页(Webview)-Web View Controller"包含了一个实现网页浏览功能的示例项目,适用于iPhone、iPad以及iPod touch设备。在Mac环境下解压后,开发者可以深入...
在iOS中,应用通常基于Cocoa Touch框架构建,它提供了UI元素和事件处理的基础。在这个项目中,我们可以预期源码会包含Objective-C或Swift语言编写的代码,用于实现浏览器功能。 1. **项目结构**: - `AppDelegate`...
- CoreText是一个Cocoa Touch框架,用于在iOS和macOS上处理文字排版和图形渲染。 - 它提供了对Unicode字符集的支持,可以处理多种语言和特殊字符。 - CoreText使用CTFontRef和CTParagraphStyleRef等结构体来定义...
尽管TextView通常不支持HTML交互,但这个组件可能通过添加手势识别器或者监听触摸事件,使得用户能与HTML内容进行交互,例如点击链接或者图片。 8. **安全考虑** 当处理用户输入的HTML内容时,必须注意防止XSS...
Block可以捕获并存储其所在作用域内的变量,这使得Block非常适合用于异步操作的回调或者简单的事件处理。例如,使用gcd(Grand Central Dispatch)的dispatch_async方法进行异步任务,或者使用UIWebView的...
首先,我们要明白滑动效果的核心在于处理用户的触摸事件(touch events)。在iOS平台上,我们可以使用UIScrollView或UIWebView来实现页面的滚动功能。而在Android中,我们通常会使用ScrollView或NestedScrollView,...
`UIKit`提供了`UIWebView`或`WKWebView`来展示PDF内容,而`CoreGraphics`则提供了低级别的图形接口,可以直接处理PDF文件的加载和渲染。 1. **UIWebView与WKWebView**: - `UIWebView`:旧版的网页视图控制器,...
《iPhoneOpe》将深入探讨Cocoa Touch中的关键概念,如UIViewController、UIWebView、UITableView等,这些都是构建iPhone应用界面不可或缺的部分。此外,还会讲解手势识别、动画效果和多任务处理,使开发者能够创建出...
5. **用户交互**:iOS提供了丰富的手势识别和事件处理机制。例如,滑动翻页、捏合缩放等手势可以增强用户体验。`UIPanGestureRecognizer`、`UIPinchGestureRecognizer`等类可以实现这些功能。 6. **版本控制与更新*...
3. **Cocoa Touch框架**:Cocoa Touch是iOS应用程序的基础,包含了一系列用于构建用户界面和处理事件的类。书中将详细解释各个关键组件如UIViewController、UIWebView、UITableView等的使用方法。 4. **iOS架构与...
在iOS项目中,你需要在Xcode中创建一个新的Cocoa Touch Class,用于处理OAuth相关的网络请求。这个类通常会继承自`UIViewController`或`UITableViewController`,并包含一个`UIWebView`用于显示授权页面。在初始化这...
13. **Cocoa Touch**:Cocoa Touch是iOS应用开发的基础框架,包含了UI组件、触摸事件处理、动画等,如OpenAL(音频处理)、Bonjour(发现网络服务)、WebKit(网页渲染)和BSD Sockets(网络编程接口)都是在其上...
它提供了创建用户界面、处理事件、网络通信、多媒体支持等功能。在源代码中,你可以看到如何使用UIViewController、UITableView、UIButton等控件构建应用程序的界面。 3. **Xcode**: Apple的集成开发环境(IDE),...
2. **Cocoa Touch框架**: Cocoa Touch是iOS应用的UI构建基石,包括UIKit、Foundation等子框架。书中会讲解如何使用UIViewController管理屏幕内容,UIWebView加载网页,UITableView展示列表,以及UIButton、UILabel、...
- 项目基于Apple的iOS SDK,其中包括了Xcode IDE和Cocoa Touch框架,它们提供了构建用户界面和处理系统服务的工具和API。 2. **UI设计与交互**: - `Classes`目录可能包含了自定义的视图控制器,用于实现不同的...