Thursday 29 January 2015

Siri lables animation in ios

In viewDidload ..... 

   NSArray *labeltexttoanimate = @[@"Awesome",@"Animation",@"Like...",@"Siri......"];
    
    [self animateLabels: labeltexttoanimate];

- (void)animateLabels:(NSArray *)labels
{
   
    NSLog(@"the data in the labels is %@",labels);

    CGFloat firstLabelStartTop = 600;
    
    [labels enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)

{
       
CGFloat delay = 0.15 * idx;

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(150, firstLabelStartTop + 30 * idx, 320, 21)];

        label.text = obj;

        label.alpha = 0.0;

        [self.view addSubview:label];
        
        [UIView animateKeyframesWithDuration:2.4
                                       delay:delay
                                     options:0
                                  animations:^{
                                      [UIView addKeyframeWithRelativeStartTime:0.0
                                                              relativeDuration:0.2
                                                                    animations:^{
                                                                        label.alpha = 1.0;
                                                                        label.frame = CGRectOffset(label.frame, 0, -400);
                                                                    }];

                                      [UIView addKeyframeWithRelativeStartTime:0.2
                                                              relativeDuration:2.0
                                                                    animations:^{
                                                                        label.frame = CGRectOffset(label.frame, 0, -200);
                                                                    }];
                                      
                                      [UIView addKeyframeWithRelativeStartTime:0.5
                                                              relativeDuration:0.2
                                                                    animations:^{
                                                                        label.alpha = 0.0;
                                                                        label.frame = CGRectOffset(label.frame, 0, -200);
                                                                    }];
                                  }
                                  completion:^(BOOL finished)
                                 {
                                   
                                  }];
    }];
    

}