Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6369827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:51:13+00:00 2026-05-25T00:51:13+00:00

I am working on a Kid’s Book App for iPad. It has a UIView

  • 0

I am working on a Kid’s Book App for iPad. It has a UIView which loads UIImageView to display UIImages (JPEG’s), user can swipe on images to browse through pages – everything works fine. Now I wanted to add some interactivity to some of the pages by adding another UIImageView which would load a PNG file and on Tap Gesture I want to animate them… Below is the code snippet…

I added a Tap Gesture to UIView inside viewDidLoad. viewDidLoad calls loadPage and inside loadPage I am programatically adding a UIImageView (imageAnimation) containing a PNG file and also assigning a tag to it so that I can play animations based on tags inside handleTap routine. For some reason, the switch statement in handleTap execute ONLY for case 1, for other cases handleTap routine is NEVER called. What wrong am I doing?

#import "KidsViewController.h"

@implementation KidsViewController
@synthesize imageAnimation;

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[UISlider class]] || [touch.view isKindOfClass:[UIButton class]])
    {
        return NO;
    }
    return YES;
}

- (void)handleTap:(UITapGestureRecognizer *)recognizer {

    NSLog(@"KidsViewController ==> handleTap.");

    switch (((UIGestureRecognizer *)recognizer).view.tag)      
    {
        case 1:
            //...
            NSLog(@"KidsViewController ==> handleTap. Switch Case: %d", 1);
            break;
        case 2:
            //...
            NSLog(@"KidsViewController ==> handleTap. Switch Case: %d", 2);
            break;
        case 3:
            //...
            NSLog(@"KidsViewController ==> handleTap. Switch Case: %d", 3);
            break;            
        default:
            NSLog(@"KidsViewController ==> handleTap. Switch Case: DEFAULT");
            break;
    }

}

- (void)viewDidLoad {

    pageCount=12;
    pageNum=1;

    //put imageviews in place
    imageNext.frame=CGRectMake(0,0-crop,screenwidth,screenheight+(crop*2));
    imageCurrent.frame=CGRectMake(0,0-crop,screenwidth,screenheight+(crop*2));

    [self loadPage];

    imageCurrent.image = [UIImage imageWithContentsOfFile:[self filePathForLanguage:language pageNumber:pageNum fileType:@"jpg"]];

    //TAP GESTURE
    UITapGestureRecognizer *tapRecognizer;
    tapRecognizer=[[UITapGestureRecognizer alloc] 
                   initWithTarget:self
                   action:@selector(handleTap:)];
    tapRecognizer.numberOfTapsRequired=1;
    tapRecognizer.numberOfTouchesRequired=1;
    [self.imageAnimation addGestureRecognizer:tapRecognizer];
    tapRecognizer.delegate = self;
    [tapRecognizer release];
}

-(void)loadPage{

    imageNext.image = [UIImage imageWithContentsOfFile:[self filePathForLanguage:language pageNumber:pageNum fileType:@"jpg"]]; //[UIImage imageWithContentsOfFile:pathFilename];

    switch (pageNum)      
    {
        case 1:
            //...
            NSLog(@"KidsViewController ==> loadPage. Switch Case: %d", pageNum);
            UIImage *image = [UIImage imageNamed:@"P3-stilts_00000.png"];
            CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
            imageAnimation = [[UIImageView alloc] initWithFrame:frame];
            imageAnimation.userInteractionEnabled = YES;
            imageAnimation.image = image;
            imageAnimation.tag = pageNum;
            [self.view addSubview:imageAnimation];
            [image release];
            break;
        case 2:
            //...
            NSLog(@"KidsViewController ==> loadPage. Switch Case: %d", pageNum);
            imageAnimation.image = nil;
            [imageAnimation setCenter:CGPointMake(-100,-100)];
            break;
        case 3:
            //...
            NSLog(@"KidsViewController ==> loadPage. Switch Case: %d", pageNum);
            UIImage *image3 = [UIImage imageNamed:@"bug.png"];
            CGRect bugFrame = CGRectMake(0, 0, image3.size.width, image3.size.height);
            imageAnimation = [[UIImageView alloc] initWithFrame:bugFrame];
            imageAnimation.userInteractionEnabled = YES;
            imageAnimation.image = image3;
            imageAnimation.tag = pageNum;
            [self.view addSubview:imageAnimation];
            [image3 release];
            break;            
        default:
            NSLog(@"KidsViewController ==> loadPage. Switch Case: DEFAULT");
            [imageAnimation setCenter:CGPointMake(-100,-100)];
            break;
    }
}

- (void)dealloc {
    [setupViewController release];
    [imageCurrent release];
    [imageNext release];
    [imageShadow release];
    [imageMenuBar release];
    [imageAnimation release];
    [super dealloc];
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:51:13+00:00Added an answer on May 25, 2026 at 12:51 am

    You always get tag of your self.view. It’s tag by default is 0. So switch jumps to default option.

    You can add your recognizer to imageAnimation and it will work fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on my first EmberJS app. The entire app requires that a user be
I'm working on my first Android app, a math game for my kid, and
Working in Drupal today and simple cell spacing has been anything but simple for
Working in Java FX 2.2. The Scene has a horizontal width that is fixed
Newbie working on his first rails application after studying Hartl's Rails Tutorial book &
Working on an app using Akka 2 deployed with Play-mini. I pulled logback into
Working in Scala-IDE, I have a Java library, in which one of the methods
Working on a multi-tenant app where most of my models will have a tenant_id
Working in an app where a page_title method was defined in application_helper.rb as such:
Working on a website http://www.ArenaText.com written in asp.net with Microsoft AJAX control toolkit. iPad

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.