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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:07:46+00:00 2026-05-15T07:07:46+00:00

I’m making a partial overlay modal in my app with the code from Semi-Modal

  • 0

I’m making a partial overlay modal in my app with the code from “Semi-Modal (Transparent) Dialogs on the iPhone” at ramin.firoozye.com. In doing so, the button that calls the modal is still visible and clickable. I will hide this button when the modal spawns, but I want to be sure if the user clicks very quickly twice, a new modal doesn’t come up for each click. What is the best way to check that the modal doesn’t already exist when calling it from the button click?

You can download the test project here. For those that don’t have xcode, the relevant functions are below:

I call forth the modal on button click with this:

- (IBAction)displayModal:(id)sender {
    ModalViewController *modalController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
    modalController.view.frame = CGRectOffset(modalController.view.frame, 0, 230);
    [self showModal:modalController.view];
}

Then use this function to animate the custom modal over the current view:

- (void)showModal:(UIView*) modalView {
    UIWindow* mainWindow = (((TestAppDelegate*) [UIApplication sharedApplication].delegate).window);

    CGPoint middleCenter = modalView.center;
    CGSize offSize = [UIScreen mainScreen].bounds.size;
    CGPoint offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
    modalView.center = offScreenCenter; // we start off-screen
    [mainWindow addSubview:modalView];

    // Show it with a transition effect
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.4]; // animation duration in seconds
    modalView.center = middleCenter;
    [UIView commitAnimations];
}

Then I dismiss the modal on button click with this:

- (IBAction)dismissModal:(id)sender {
    [self hideModal:self.view];
}

And then use these functions to animate the modal offscreen and clean itself up:

- (void)hideModal:(UIView*) modalView {
    CGSize offSize = [UIScreen mainScreen].bounds.size;
    CGPoint offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
    [UIView beginAnimations:nil context:modalView];
    [UIView setAnimationDuration:0.7];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(hideModalEnded:finished:context:)];
    modalView.center = offScreenCenter;
    [UIView commitAnimations];
}

- (void)hideModalEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    UIView* modalView = (UIView *)context;
    [modalView removeFromSuperview];
    [self release];
}

Any help is greatly appreciated!

  • 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-15T07:07:46+00:00Added an answer on May 15, 2026 at 7:07 am

    I really didn’t want to resort to a global variable to keep track of the modal already existing, so I decided to use notification.

    I put this in my navigation controller where I call the modal:

    - (void)viewDidLoad {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notShowingModal) name:@"ModalDidClose" object:nil];
        [super viewDidLoad];
    }
    
    - (void)notShowingModal {
        isShowingModal = NO;
    }
    

    Then I put this in the modal controller where the modal is dismissed:

    - (void)viewDidDisappear:(BOOL)animated {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"ModalDidClose" object:nil];
    }
    

    I could probably do it with the AppDelegate as well. If anyone thinks that, or anything else, would be a better fit for this, let me know.

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

Sidebar

Ask A Question

Stats

  • Questions 440k
  • Answers 440k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'll assume you meant Arial. That font is not available… May 15, 2026 at 5:06 pm
  • Editorial Team
    Editorial Team added an answer You cannot correctly validate an email address with regular expressions… May 15, 2026 at 5:06 pm
  • Editorial Team
    Editorial Team added an answer necesarry: no does it make sense: sure, why not? No… May 15, 2026 at 5:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.