首页 > 代码库 > 类似刷新微博后,顶部显示更新数量的动画。

类似刷新微博后,顶部显示更新数量的动画。

@interface welcomeLabel : UILabel

 

+(void)setTopTipLabelWithFrame:(CGRect)frame name:(NSString *)name andNavController:(UINavigationController *)nav;

 

@end

 

#import "welcomeLabel.h"

 

@implementation welcomeLabel

 

+ (void)setTopTipLabelWithFrame:(CGRect)frame name:(NSString *)name andNavController:(UINavigationController *)nav{

 

    id obj = [[welcomeLabel alloc]initWithFrame:frame name:name andNav:nav];

    

}

 

- (instancetype)initWithFrame:(CGRect)frame name:(NSString *)name andNav:(UINavigationController *)nav;

    if (self = [super initWithFrame:frame])

    {

        [nav.view insertSubview:self belowSubview:nav.navigationBar];

        self.text = [NSString stringWithFormat:@"欢迎回来,%@",name];

        self.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.7];

        self.textAlignment = NSTextAlignmentCenter;

        self.textColor = [UIColor blackColor];

        self.font = [UIFont systemFontOfSize:17];

        [self setupLabel];

    }

    return self;

}

 - (void)setupLabel

{   

    int w = self.bounds.size.width;

    int h = 35;

    int x = 0;

    int y = 64 - h;

    self.frame = CGRectMake(x, y, w, h);

    CGFloat duration = 0.7;

    self.alpha = 0.0;

    [UIView animateWithDuration:duration animations:^{

        self.transform = CGAffineTransformMakeTranslation(0, h);

        self.alpha = 0.7;

 

    } completion:^(BOOL finished) {

        

        CGFloat delay = 1.5;

        

        [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:^{

            

            self.transform = CGAffineTransformIdentity;

            self.alpha = 0.0;

            

        } completion:^(BOOL finished) {

            

            [self removeFromSuperview];

            

        }];

}]; 

}

@end

 使用的时候 直接使用类方法即可。

类似刷新微博后,顶部显示更新数量的动画。