【发布时间】:2014-02-23 12:58:02
【问题描述】:
我在我的视图中识别出触摸 - 如果发生某些情况,我想用这个方法调用我的子视图,但它不起作用 - (如果我不覆盖 hittestWithEvent - 这个视图会被返回)
我该怎么做?
编辑:
我希望原始的 SUBVIEW 获得“点击”,所以我尝试这样做:
-(void)didTap:(MyTapGesture *)tap
{
// the original view that would have been returned by hit test. could be any arbitrary view
UIView *theView = [super hitTest:[tap locationInView:self] withEvent:nil];
NSSet *touchesBegan = tap.touchesBegan;
NSSet *touchesEnded = tap.touchesEnded;
UIEvent *eventBegan = tap.eventBegan;
UIEvent *eventEnd = tap.eventEnd;
NSSet *tbegan = [eventBegan touchesForView:theView];
NSSet *tend = [eventEnd touchesForView:theView];
// try to simulate the touch in the subview - not working
[theView touchesBegan:tbegan withEvent:eventBegan];
[theView touchesEnded:tend withEvent:eventEnd];
}
@interface MyTapGesture : UITapGestureRecognizer
@property (nonatomic,strong) NSSet *touchesBegan;
@property (nonatomic,strong) NSSet *touchesEnded;
@property (nonatomic,strong) UIEvent *eventBegan;
@property (nonatomic,strong) UIEvent *eventEnd;
@end
@implementation MyTapGesture
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.touchesBegan = touches;
self.eventBegan = event;
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
self.touchesEnded = touches;
self.eventEnd = event;
[super touchesEnded:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
}
@end
【问题讨论】:
-
你的视图和子视图是什么子类(是UIView)?请发布一些代码。
-
两者都是自定义视图 - 每个都包含一些控件
标签: ios objective-c uitouch uiresponder