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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:17:34+00:00 2026-06-08T08:17:34+00:00

I have a simple app which consists of 2 views. Top view has a

  • 0

I have a simple app which consists of 2 views. Top view has a accelerometer delegates. when user shakes while top view is on the screen. then pushviewcontroller is called and subview will appear. the problem is when subview is appeard, i shake it, it still catches the shake action and results me an error. So help me. thanks in advance.

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
const float violence = 1.2;
static BOOL beenhere;
BOOL shake = FALSE;

if (beenhere) return;
beenhere = TRUE;

if (acceleration.x > violence || acceleration.x < (-1* violence))
    shake = TRUE;
if (acceleration.y > violence || acceleration.y < (-1* violence))
    shake = TRUE;
if (acceleration.z > violence || acceleration.z < (-1* violence))
    shake = TRUE;
if (shake) {
    [self playSound:@"suzu"];

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"noVib"] == NO) {
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    }
    [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
    [self presentModalViewController:mMoviePlayer animated:YES];
    [self play]; 
}

when play method called and video has finished, pushviewcontroller will be called and the sub view will appear

below is a class that handles all the movieplayer stuff.

- (void) initPlayer{
if (mMoviePlayer != nil){
    [mMoviePlayer release];
}

mMoviePlayer = [[MoviePlayerViewController alloc] initWithContentURL:[self createURL]];
[[NSNotificationCenter defaultCenter] removeObserver:mMoviePlayer 
                                                name:MPMoviePlayerPlaybackDidFinishNotification object:mMoviePlayer.moviePlayer];
[mMoviePlayer.moviePlayer setShouldAutoplay:NO];
mMoviePlayer.moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
mMoviePlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
mMoviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayBackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:mMoviePlayer.moviePlayer];

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePreloadDidFinish:) 
                                             name:MPMoviePlayerLoadStateDidChangeNotification 
                                           object:mMoviePlayer.moviePlayer];

- (void) moviePlayBackDidFinish:(NSNotification*)notification

{

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];        
[[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:mMoviePlayer.moviePlayer];
[self dismissModalViewControllerAnimated:YES];
[mMoviePlayer release];
mMoviePlayer = nil;
[self toNext];

}

  • 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-08T08:17:35+00:00Added an answer on June 8, 2026 at 8:17 am

    The first thing that comes into my mind is to keep track if the mMoviePlayer is pushed or not.

    if (shake && mPlayerPushed) {
        [self playSound:@"suzu"];
    
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"noVib"] == NO) {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
        }
        [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
        [self presentModalViewController:mMoviePlayer animated:YES];
        [self play]; 
        mPlayerPushed = YES;
    }
    

    in the moviePlayBackDidFinish method after you call dismissModalViewControllerAnimated:YES you should set the mPlayerPushed to NO.

    or you could use the property modal view controller to see if a modal view is displayed. This i haven’t tested yet but it should work.

    modalViewController: The controller for the active modal view—that is,
    the view that is temporarily displayed on top of the view managed by
    the receiver. (read-only)

    @property(nonatomic, readonly) UIViewController *modalViewController
    

    so instead of the bool mPlayerPushed you will have:

    if(shake && something.modalviewController == nil){ present mMoviePlayer }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple rails app: I have 2 models, user and intro [which is simply a
I have a simple navigation based app which has a bunch fo forms in
I have a simple wpf app which has a button that increments a value
I have a simple app, which opens a modal view to send email. Am
I have a simple project which consists of a simple window with one view
I have this app which consists of three tabs. The first tab has a
I have a simple app which adds a subview over the main view when
We have a simple java app which runs user requests (commands) on the command
I have a simple Silverlight app which simply sets a DataGrid's ItemsSource to the
I have managed to create a simple app which deletes (bypassing the recycle bin)

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.