Search code examples
iosiphone-5

When I tap on a image its not working properly from iphone 5s


I added an image to a button. I am using gestures for animating the image in my sample app. It was working fine with iPhone 4, 4s, and 5 but the problem arise from iphone 5s.

` -(void)awakeFromNib
 {
  [super awakeFromNib];

   UITapGestureRecognizer *tapGestureRecognizer =                  [[UITapGestureRecognizer alloc] initWithTarget:self     action:@selector(characterImagedTapped)];

 self.characterImageView.userInteractionEnabled = YES;
 [self.characterImageView addGestureRecognizer:tapGestureRecognizer];

}

Here is the characterImagedTapped function,

' -(void) characterImagedTapped { if ([self.delegate respondsToSelector:@selector(didCharacterTapped:)]) [self.delegate performSelector:@selector(didCharacterTapped:)]; } ' this function is calling didCharacterTapped.

When I tapped on the button it will call didCharacterTapped function it's implementation as below:
-(void)didCharacterTapped:(BOOL)tapped    
{
    if (tapped && !isCharacterAnimating) {
        [self startWelcomeBackCharacterAnimation];
    }
}`

If tapped value is YES it will call startWelcomeBackCharacterAnimation. If it is NO it will skip and the image will not get animated.

Actually when I tapped on the button the tapped boolean value should be YES, but the tapped bool value always shows NO from iPhone 5s version.


Solution

  • -(void) characterImagedTapped
    {
        if ([self.delegate respondsToSelector:@selector(didCharacterTapped:)]) {
            [self.delegate performSelector:@selector(didCharacterTapped:) withObject:[NSNumber numberWithBool:YES]];
        }
        else {
            [self.delegate performSelector:@selector(didCharacterTapped:) withObject:[NSNumber numberWithBool:NO]];
        }
    }
    
    -(void)didCharacterTapped:(NSNumber *)tapped
    {
         if (tapped.boolValue) {
        //[self startWelcomeBackCharacterAnimation];
         }
        else {
        }
    }
    

    You can perform the selector with object and in the selector you can access the object value as per the above code