0

I want to create a custom alertView that works like instagram app (login/signin view when user enters wrong password or email). The alert animation should drop down and pause for the user to read for about 2 seconds, then the alertView goes up again. How can I do this?

Here is what I have now:

- (UIView *) createAlertViewWithViewController:(UIViewController *)viewController andText:(NSString *)alertText
{
    alertView = [[UIView alloc] init];
    [alertView setBackgroundColor:ALERT_VIEW_COLOR];
    [alertView setFrame:ALERT_VIEW_HIDE_FRAME];


    UILabel *alertViewLabel = [[UILabel alloc] init];
    [alertViewLabel setFrame:CGRectMake(viewController.view.bounds.origin.x, 7, viewController.view.bounds.size.width, ALERT_VIEW_HEIGHT)];
    [alertViewLabel setTextAlignment:NSTextAlignmentCenter];
    [alertViewLabel setTextColor:[UIColor whiteColor]];
    [alertViewLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [alertViewLabel setText:alertText];
    [alertView addSubview:alertViewLabel];

    CGPoint originalCenter = alertView.center;
    [UIView animateWithDuration:0.5
                     animations:^{
                         CGPoint center = alertView.center;
                         center.y += ALERT_VIEW_HEIGHT;
                         alertView.center = center;
                     }
                     completion:^(BOOL finished){

                         [UIView animateWithDuration:3.0
                                          animations:^{
                                              alertView.center = originalCenter;
                                          }
                                          completion:^(BOOL finished){
                                              ;
                                          }];

                     }];

    return alertView;
}

My code right now goes down and goes up immediately but what I want is, when it finishes the drop down animation it pauses for around 2 seconds then do the goes up animation.

I have been searching for 3 days now, but I haven't found anything one this.

Example image when it should pause for 2 seconds:

enter image description here

3 Answers3

0

Would you like a this library?
https://github.com/problame/CSNotificationView

Example

[CSNotificationView showInViewController:self
    tintColor:[UIColor colorWithRed:0.000 green:0.6 blue:1.000 alpha:1]
        image:nil
      message:@"What's the meetup called?"
     duration:2.f];
yuki tamazawa
  • 21
  • 1
  • 4
0

Im guessing you are looking for one of the extended versions of [UIView animateWithDuration:...

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

Pass in a delay to wait your animation.

Warren Burton
  • 17,451
  • 3
  • 53
  • 73
0

Try this:

UILabel *myLable=[[UILabel alloc]init];
myLable.frame=CGRectMake(0, -50, 320, 50);
myLable.backgroundColor=[UIColor grayColor];
myLable.textAlignment=NSTextAlignmentCenter;
myLable.text=@"Your Error Message";
[self.view addSubview:myLable];

[self ShowAnimation:myLable currentFrame:CGRectMake(0, -50, 320, 50) newFrame:CGRectMake(0, 0, 320, 50)];

.

-(void)ShowAnimation:(UILabel *)aLable currentFrame:(CGRect)aCurrentFrame newFrame:(CGRect)aNewFrame
{
    [aLable setFrame:aCurrentFrame];
    [UIView animateWithDuration:1.5 animations:^{
        [aLable setFrame:aNewFrame];
    }completion:^(BOOL finished)
        {
            [aLable setFrame:aNewFrame];

            [UIView animateWithDuration:1.5 delay:2.0 options:UIViewAnimationOptionCurveEaseIn
                         animations:^{
                                [aLable setFrame:aCurrentFrame];
                            }
                             completion:^(BOOL finished) {
                             }];
        }];    
}
Yasika Patel
  • 6,356
  • 3
  • 19
  • 21
  • Thanks yaiska, your answer also helped. I'd like to vote up but I can't, not enough reputation. :\ –  Aug 27 '14 at 11:44