The main disadvantage in the object UIWebView is lack of methods touchBegan and touchEnd. But this question has been settled by some manipulations with privates possibilities:) Thank you Satoshi Nakagawa :)
PSWebView.h – empty
1
2
3
4
5
|
#import
@interface PSWebView : UIWebView
@end
</uikit>
|
If you need add method touchBegan then make step by step
1. add after 6 line
1
|
- (void)webView:(UIWebView*)sender tappedBeganWithTouch:(UITouch*)touch event:(UIEvent*)event;
|
2. after 11
1
|
- (void)fireBeganTappedWithTouch:(UITouch*)touch event:(UIEvent*)event;
|
3. add after 31
1
2
3
4
5
6
7
8
9
10
11
|
- (void)__touchesBegan :(NSSet*)touches withEvent :(UIEvent *)event
{
[self __touchesBegan :touches withEvent :event ];
id webView = [[self superview ] superview ];
if (touches.count == 1) {
if ([webView respondsToSelector :@selector(fireBeganTappedWithTouch :event :)]) {
[webView fireBeganTappedWithTouch :[touches anyObject ] event :event ];
}
}
}
|
4. after 46
1
2
3
|
Method targetMethod2 = class_getInstanceMethod(klass, @selector(touchesBegan:withEvent:));
Method newMethod2 = class_getInstanceMethod(klass, @selector(__touchesBegan:withEvent:));
method_exchangeImplementations(targetMethod2, newMethod2);
|
5. and last addition in source before last “@end”
1
2
3
4
5
6
|
- (void)fireBeganTappedWithTouch :(UITouch *)touch event :(UIEvent *)event
{
if ([self.delegate respondsToSelector :@selector(webView :tappedBeganWithTouch :event :)]) {
[(NSObject*)self.delegate webView :self tappedBeganWithTouch :touch event :event ];
}
}
|
For touchMoves similar steps. It’s easy!
Continue reading →