gpt4 book ai didi

iphone - 未调用 UISwipeGestureRecognizer 选择器。知道为什么吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:05 27 4
gpt4 key购买 nike

我正在使用下面的代码将右/左滑动事件集成到 UIImageView 对象(称为 photo_view),但在 iphone 模拟器和设备中测试后它不起作用。下面的方法 handleLeftSwipehandleRightSwipe 甚至没有被调用,因为日志记录没有在调试器日志中打印任何它应该打印的内容。这是代码:

- (void)viewDidLoad
{
[super viewDidLoad];

UISwipeGestureRecognizer *leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
leftSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
leftSwipeRecognizer.numberOfTouchesRequired = 1;
[photo_view addGestureRecognizer:leftSwipeRecognizer];
leftSwipeRecognizer.delegate = self;
[leftSwipeRecognizer release];

UISwipeGestureRecognizer *rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
rightSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
rightSwipeRecognizer.numberOfTouchesRequired = 1;
[photo_view addGestureRecognizer:rightSwipeRecognizer];
rightSwipeRecognizer.delegate = self;
[rightSwipeRecognizer release];

}


- (void)handleLeftSwipe:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"handleLeftSwipe called");
}

- (void)handleRightSwipe:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"handleRightSwipe called");
}

知道是什么原因吗?

提前感谢您的帮助,

史蒂芬

最佳答案

UIImageView 实例默认 userInteractionEnabledNO。尝试将其设置为 YES

关于iphone - 未调用 UISwipeGestureRecognizer 选择器。知道为什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8011708/

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