gpt4 book ai didi

ios - 禁用手势识别器

转载 作者:可可西里 更新时间:2023-11-01 03:37:46 25 4
gpt4 key购买 nike

我有一个简单的内存游戏。但是我想关闭点击功能。

当我使用 imageViewGurka1.gestureRecognizers=NO; 时它有效,但我收到警告消息:Initialization of pointer of type 'NSArray *' to null from a constant boolean expression。 (我应该怎么做才能修复此警告消息?)

如果我使用此 imageViewGurka1 setUserInteractionEnable:NO; 我不会收到警告消息,但我将无法再移动图像。

这是一些代码。

-(IBAction)handleTapGurka1:(UIGestureRecognizer *)sender {

if (imageViewGurka1.tag == 0) {
[imageViewGurka1 setImage:[UIImage imageNamed:@"memorySångerGurka.png"]];
imageViewGurka1.tag=1;
[self.view bringSubviewToFront:imageViewGurka1];

}

else {
[imageViewGurka1 setImage:[UIImage imageNamed:@"memorySångerBaksida.png"]];
imageViewGurka1.tag=0;
[self.view bringSubviewToFront:imageViewGurka1];
}

if (imageViewGurka1.tag==1 && imageViewGurka2.tag==1) {
NSURL *musicFile;
musicFile = [NSURL fileURLWithPath:
[[NSBundle mainBundle]
pathForResource:@"applader"
ofType:@"mp3"]];
myAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[myAudio play];
//[imageViewGurka1 setUserInteractionEnabled:NO];
//[imageViewGurka2 setUserInteractionEnabled:NO];
imageViewGurka1.gestureRecognizers=NO;
imageViewGurka2.gestureRecognizers=NO;
}

}

感谢您的帮助!

问候

最佳答案

gestureRecognizers 是一个数组,其中包含附加到 View 的所有手势识别器。您应该遍历该数组中的所有手势识别器并将它们的 enabled 属性设置为 false,如下所示:

for (UIGestureRecognizer * g in imageViewGurka1.gestureRecognizers) {
g.enabled = NO;
}

swift 5

低于 Swift 5 的等效值

for gesture in imageViewGurka1.gestureRecognizers! {
gesture.isEnabled = false
}

关于ios - 禁用手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28442706/

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