gpt4 book ai didi

ios - 我可以打电话 - (void)touchesBegan :(NSSet *)touches withEvent:(UIEvent *)event on subview

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:16 28 4
gpt4 key购买 nike

我在我的 View 中识别触摸 - 如果某些情况发生我想用这个方法调用我的 subview 但它不起作用 - (如果我不覆盖 hittestWithEvent - 这个 View 将被返回)

我该怎么做?

编辑:

我想让原来的 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

最佳答案

您可以在您的主视图上覆盖 touchesBegan:withEvent 并在条件发生时在您的 subview 上调用它:

//In your view
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (CONDITION)
{
//call your subview
[yourSubview touchesBegan:touches withEvent:event];
}
}

希望这就是您所追求的。

//扩展

您可以尝试向您的 subview 添加一个方法,该方法在满足条件时调用:

//In your subview
-(void)myMethod:(NSSet *)touches
{
//Your code
}

并在你的 View 中调用它:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (CONDITION)
{
//call your subview
[yourSubview myMethod:touches];
}
}

关于ios - 我可以打电话 - (void)touchesBegan :(NSSet *)touches withEvent:(UIEvent *)event on subview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21968515/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com