gpt4 book ai didi

ios - 如何忽略滑动手势使用 touchBegan

转载 作者:行者123 更新时间:2023-11-29 12:08:28 26 4
gpt4 key购买 nike

当我每次触摸屏幕时都运行这个程序,我希望球向下移动。问题是每次我这样做时,滑动手势(向右移动)也会在我不想要时识别触摸。这将导致球向侧面移动(应用触摸和滑动)。

有没有办法忽略滑动手势,让我的 touchBegan 单独存在。

ViewController.h

int MoveBallRight;
int MoveBallDown;
@interface ViewController : UIViewController{

__weak IBOutlet UIImageView *Ball;

__weak IBOutlet UIButton *StartButton;

}
- (IBAction)StartButton:(id)sender;


@end

ViewController.m

@interface ViewController ()

@end

@implementation ViewController

- (IBAction)StartButton:(id)sender {
MoveBallRight = 30;
MoveBallDown = 30;


StartButton.hidden = YES;


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



}
-(void)handleSwipeRight{

Ball.center = CGPointMake(Ball.center.x + MoveBallRight, Ball.center.y);

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

Ball.center = CGPointMake(Ball.center.x , Ball.center.y + MoveBallDown);

}
- (void)viewDidLoad {
[super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end

最佳答案

这可能有帮助

swipeRight.cancelsTouchesInView = YES

关于ios - 如何忽略滑动手势使用 touchBegan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34220107/

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