【问题标题】:Xcode, Not able to detect SwipeGesture after i add Animation on my ScrollViewXcode,在我的 ScrollView 上添加动画后无法检测到 SwipeGesture
【发布时间】:2026-01-03 09:15:02
【问题描述】:

开始之前,

UISwipeGestureRecognizer *seipeges=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftswipe:)];
    seipeges.direction=UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:seipeges];

    UISwipeGestureRecognizer *rightgesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightswipe:)];
    rightgesture.direction=UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:rightgesture];

此滑动检测代码运行良好。 之后我在 UIScrollView 上添加动画。

[UIView animateWithDuration:3.0f
                      delay:0.0f
                    options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
                 animations:^{
                     if(leftright==1)
                         [imgCell.scrollview setContentOffset:CGPointMake((-newOffSetX), 0)];
                     else
                         [imgCell.scrollview setContentOffset:CGPointMake(0, 0)];
                 }
                 completion:^(BOOL finished){
                 }];

动画也运行良好。 如果动画尚未开始,则 UISwipeGestureRecognizer 仍然运行良好。 然后我发现,当动画开始时,它不再能够检测到 UISwipeGestureRecognizer。

所以任何人都可以告诉我我错过了什么?或者为什么动画开始后 SwipeGesture 代码无法运行?

【问题讨论】:

  • 尝试将UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction 设置为该选项,看看它是否有效。
  • @Casey,谢谢!它的作品!

标签: objective-c xcode uiscrollview uiswipegesturerecognizer


【解决方案1】:

我在这里发布解决方案。

尝试设置 UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction 到该选项,看看它是否有效。

【讨论】: