I have a simple memory game. But i want to turn off the tap function.
When I use imageViewGurka1.gestureRecognizers=NO;
it works, but I get the warning message: Initialization of pointer of type 'NSArray *' to null from a constant boolean expression
. (what should I do to fix this warning message?)
And if I use this imageViewGurka1 setUserInteractionEnable:NO;
I don't get a warning message, but I will not be able to move the image any more.
Here is some of the code.
-(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;
}
}
Thanks for any help!
Regards
gestureRecognizers
is an array that contains all gesture recognizers attached to the view. You should loop through all gesture recognizers in that array and set their enabled
property to false like this:
for (UIGestureRecognizer * g in imageViewGurka1.gestureRecognizers) {
g.enabled = NO;
}
Swift 5
Below the equivalent for Swift 5
for gesture in imageViewGurka1.gestureRecognizers! {
gesture.isEnabled = false
}