Fred Collins
Fred Collins

Reputation: 5010

iPhone loading view "slide effect"

I would to achieve that when you request something in my app (like a button pressed or whatever) I would like it to appear a small rectangle that says "loading.." and when the loading is completed it disappear with a "slide up effect". I've made a simple mockups for describing well what I'm trying to achieve. Do you have any hint for me? Thanks.

enter image description here

NOTE: I don't want pull to refresh effect (the loading view appears without the screen scrolling, it appears for example when you send a comment)

UPDATE:

I've tried the Cirrostratus code:

- (IBAction)displayLoadingScreen:(id)sender
{
    NSLog(@"pressed");
    UIView *loadingView = [[UIView alloc] init];
    loadingView.frame = CGRectMake(0,-40,320,40);
    [loadingView setBackgroundColor:[UIColor blueColor]];
    [self.view addSubview:loadingView];
    //animate in within some method called when loading starts
    [UIView animateWithDuration:1.0
                     animations:^{ 
                         loadingView.frame = CGRectMake(0,0,320,40);
                     } 
                     completion:^(BOOL finished) {
                     }];
    for (int i = 0; i < 10000; i++) {
        NSLog(@"%d", i);
    }
    //animate out within some method called when loading ends
    [UIView animateWithDuration:1.0
                     animations:^{ 
                         loadingView.frame = CGRectMake(0,-40,320,40);
                     } 
                     completion:^(BOOL finished){


                     }];
}

Why the loading view slide in after the for loop? If you try it, before it prints the for loop and after executes the two animations. Ideas?

UPDATE 2

- (void)stopLoading {
    [UIView animateWithDuration:1.0
                     animations:^{ 
                         loadingView.frame = CGRectMake(0,-40,320,40);
                     } 
                     completion:^(BOOL finished){
                     }];
}

- (void)startLoading {
    loadingView.frame = CGRectMake(0,-40,320,40);
    [loadingView setBackgroundColor:[UIColor blueColor]];
    [self.view addSubview:loadingView];
    //animate in within some method called when loading starts
    [UIView animateWithDuration:1.0
                     animations:^{ 
                         loadingView.frame = CGRectMake(0,0,320,40);
                     } 
                     completion:^(BOOL finished) {
                     }];
    sleep(5);
    [self stopLoading];
}

- (IBAction)displayLoadingScreen:(id)sender
{
    NSLog(@"button pressed");
    [self startLoading];
}

Upvotes: 4

Views: 2856

Answers (3)

viral shah
viral shah

Reputation: 93

you can do it with the help of spinner else you take just view and set animation with its coordinate when you click on any object it will popup n your view and after completion of loading it you have to set '-' coordinate(frame) for your popup view hop it will hekp you......

Upvotes: 0

MatLecu
MatLecu

Reputation: 953

What I would do is add a view in front of your other views with the loading design you want.

Then when the loading is finished (use a notification or just call a function of the view), slide it up with that kind of animation :

[UIView animateWithDuration:0.3
                              delay:0
                            options:UIViewAnimationOptionAllowUserInteraction
                         animations:^{
                             //change the frame to make the view go out of the screen
                         }
                         completion:^(BOOL finished){
                             //do whatever you want with the view (release it for instance)
                         }];

Upvotes: 1

james_womack
james_womack

Reputation: 10296

loadingView.frame = CGRectMake(0,-40,320,40);
[loadingView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:loadingView];
//animate in within some method called when loading starts
[UIView animateWithDuration:1.0
                 animations:^{ 
                     loadingView.frame = CGRectMake(0,0,320,40);
                 } 
                 completion:^(BOOL finished){


                 }];
//animate out within some method called when loading ends
[UIView animateWithDuration:1.0
                 animations:^{ 
                     loadingView.frame = CGRectMake(0,-40,320,40);
                 } 
                 completion:^(BOOL finished){


                 }];

Upvotes: 5

Related Questions