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

  • SEARCH
  • Home
  • 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 7758875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:28:49+00:00 2026-06-01T13:28:49+00:00

For a exercise I created a project to experiment with the accelerometer functions of

  • 0

For a exercise I created a project to experiment with the accelerometer functions of the iPhone. Right now when I run the app on my device it begins with a blank screen, shake the phone and a image is displayed.

I have to force close the app to clear the image. I was hoping someone could provide a solution that would make the image reset so I could repeat the process as many times as I wanted. (shake phone, display image, clear image) I’m thinking it needs a timer or something, not sure. Here is the source code. Thanks for taking the time to read and help.

//  ViewController.m
//  AccelTest
//


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

-(void)viewWillAppear:(BOOL)animated{
    [self startAccel];
    [self view];

}

-(void)viewWillDisappear:(BOOL)animated{
    [self stopAccel];
    [self view];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}


-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{

    double const kThreshold = 2.0;
//    double const kThreshold = 2.0;
    if ( fabsf(acceleration.x) > kThreshold
        || fabsf(acceleration.y) > kThreshold
        || fabsf(acceleration.z) > kThreshold){


        [self.view addSubview:[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Icon.png"]]];

    }
}


-(void)startAccel{
    UIAccelerometer * accel = [UIAccelerometer sharedAccelerometer];
    accel.delegate = self;
    accel.updateInterval = .25;
}

-(void)stopAccel{
    UIAccelerometer * accel = [UIAccelerometer sharedAccelerometer];
    accel.delegate = nil;
}


@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-06-01T13:28:50+00:00Added an answer on June 1, 2026 at 1:28 pm

    Here is how I would do it (without ARC) to tap the image to make it disappear.

    Remove your line:

    [self.view addSubview:[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Icon.png"]]];
    

    And add these lines instead:

    UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon.png"]];
    myImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rm:)];
    [myImageView addGestureRecognizer:tapgr];
    [tapgr release]; tapgr = nil;
    [self.view addSubview:myImageView];  
    [myImageView release]; myImageView = nil;
    

    Then add a method to the View Controller to remove the UIImageView when it is tapped.

    -(void)rm:(UITapGestureRecognizer *)tapgr {
        [tapgr.view removeFromSuperview];
    }
    

    When that Image is tapped once, the rm: method will be called which will remove the Image from self.view

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

Sidebar

Related Questions

I created a bare bones iPhone app with a UIWebView (Scales Page to Fit
So I created some rspec_scaffold for an Exercise model and added map.resource :exercises to
I am new to JavaScript. I created the webpage linked below as an exercise
In order to improve my open source project, I need testers. I have created
i created an exercise program that create a dynamic menu from json. and then,
I created a word counter in Ruby as a little exercise in learning Ruby.
I am working on an exercise in operator overloading. I've created a matrix class
I created a custom project skeleton as a start for my django projects, hosted
The exercise says: Create a Text class that contains a string object to hold
Basically the exercise says Create a function which takes as an argument an array

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.