weex的通用click事件在WXComponent+Events.m中
在- (void)_addEventOnMainThread:(NSString *)addEventName方法中
WX_ADD_EVENT(click, addClickEvent) 是添加的click方法
方法触法回调
#pragma mark - Click Event
- (void)addClickEvent
{
if (!_tapGesture) {
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClick:)];
_tapGesture.delegate = self;
_tapGesture.cancelsTouchesInView = _cancelsTouchesInView;
[self.view addGestureRecognizer:_tapGesture];
}
}
- (void)onClick:(__unused UITapGestureRecognizer *)recognizer
{
NSMutableDictionary *position = [[NSMutableDictionary alloc] initWithCapacity:4];
CGFloat scaleFactor = self.weexInstance.pixelScaleFactor;
if (![self isViewLoaded]) {
return;
}
if (!CGRectEqualToRect(self.view.frame, CGRectZero)) {
CGPoint pageLocation = [recognizer locationInView:self.weexInstance.rootView];
CGRect frame = [self.view.superview convertRect:self.view.frame toView:self.view.window];
position[@"x"] = @(frame.origin.x/scaleFactor);
position[@"y"] = @(frame.origin.y/scaleFactor);
position[@"width"] = @(frame.size.width/scaleFactor);
position[@"height"] = @(frame.size.height/scaleFactor);
position[@"pageX"] = @(pageLocation.x/scaleFactor);
position[@"pageY"] = @(pageLocation.y/scaleFactor);
}
[self fireEvent:@"click" params:@{@"position":position}];
}
网友评论