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 951873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:48:16+00:00 2026-05-15T23:48:16+00:00

How can I make it so the image goes away when it is touched.

  • 0

How can I make it so the image goes away when it is touched.

Here is my code to create the image. It is randomly displayed on screen so after you touch it, it disappears and a new image in a new place appears.

-(void)drawStarsAndDetectTouches{ //uses random numbers to display a star on screen
    //create random position
    int xCoordinate = arc4random() % 267;
    int yCoordinate = arc4random() % 420;

    //make sure it doesnt draw onto titiles
    if (yCoordinate <= 40) {
        yCoordinate = arc4random() % 420;
    }

    UIImageView *starImgView = [[UIImageView alloc] initWithFrame:CGRectMake(xCoordinate, yCoordinate, 58, 40)]; //create ImageView 
    starImgView.image = [UIImage imageNamed:@"star.png"];

    [self.view addSubview: starImgView]; 

    [starImgView release];
}
  • 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-15T23:48:17+00:00Added an answer on May 15, 2026 at 11:48 pm

    From the top of my head, I can think of two ways you can achieve this.

    Either work with a UIButton instead of a UIImageView. Set the button’s type to “custom” in Interface Builder and choose your image as the background image of the button. Assign an IBAction to the button and make it invisible from your action.

    If – for whatever reason – you have to stick with an UIImageView, create a subclass that overrides -touchesBegan:inView:. Additionally, make sure that you set the image view’s userInteractionEnabled property to YES so that your -touchesBegan:inView: selector is called whenever the user touches the view. The default value of that property for UIImageView is NO so the last step is important!

    Update Here’s some sample code to get you started with the button approach in case you need to do this programmatically:

    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:img forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make a NinePatchDrawable object from a NinePatch image I made in
I'm trying to make an applet which I can simply drag an image. And
I want to make a fourier-transformation of an image. But how can I change
I don't know what's make wrong, my map can load, but the image on
I have this code for make a image search trough Google Image API: $(document).ready(function(){
I have an app that can make modify images. In some cases, this makes
When using the function imagepng() in PHP, how can I make sure the images
I can make my program write a .dat file with an array of Node
How can make a link within a facebox window that redirects it to another
I can make a single row IKImageBrowserView by setting the [imageBrowser setContentResizingMask:NSViewWidthSizable]; but in

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.