2021年2月6日星期六

Why can't the event be triggered when the iOS view moves

I tested it. When I moved the View, the tap event on the view doesn't respond, and it only responded when it stopped. I don't know why this happens. Below is my code

@interface ViewController ()  @property(nonatomic,strong)UIView *testView;  @end    @implementation ViewController    - (void)viewDidLoad {      [super viewDidLoad];            self.testView = [[UIView alloc]init];      self.testView.backgroundColor = [UIColor redColor];      self.testView.frame = CGRectMake(0, 100, 100, 100);      [self.view addSubview:self.testView];      UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTestView:)];      [self.testView addGestureRecognizer:tap];  }  - (void)tapTestView:(UITapGestureRecognizer *)tap {            NSLog(@"Event triggered");        }  - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {      [UIView animateWithDuration:6 animations:^{          CGRect frame = self.testView.frame;          frame.origin.x = 400;          self.testView.frame = frame;      }];  }  
https://stackoverflow.com/questions/66083554/why-cant-the-event-be-triggered-when-the-ios-view-moves February 07, 2021 at 08:58AM

没有评论:

发表评论