這里我已經(jīng)將這個動畫封裝成一個類方法,其中顏色,字體大小,背景圖片之類的皆可自定義。此處的動畫是建立在有navigation下方出現(xiàn),在繼而消失在navigation下方,假如想有什么多的功能,比如點(diǎn)擊彈出View跳出一個控制器等等,效果圖如下所示

效果圖
//.h文件
#import <Foundation/Foundation.h>
@interface YLAnimationShow : NSObject
+ (void)showString:(NSString *)string navigationController:(UINavigationController *)navigationController;
@end
//.m文件
#import "YLAnimationShow.h"
@implementation YLAnimationShow
+ (void)showString:(NSString *)string navigationController:(UINavigationController *)navigationController
{
UILabel *countLabel = [[UILabel alloc] init];
countLabel.backgroundColor = [UIColor purpleColor];
countLabel.width = WindowWidth;
countLabel.height = 35;
countLabel.text = string;
countLabel.textAlignment = NSTextAlignmentCenter;
countLabel.textColor = [UIColor whiteColor];
countLabel.font = [UIFont systemFontOfSize:16];
// 3.添加
countLabel.y = 64 - countLabel.height;
// 將label添加到導(dǎo)航控制器的view中,并且是蓋在導(dǎo)航欄下邊
[navigationController.view insertSubview:countLabel belowSubview:navigationController.navigationBar];
CGFloat duration = 1.0; // 動畫的時間
[UIView animateWithDuration:duration animations:^{
countLabel.transform = CGAffineTransformMakeTranslation(0, countLabel.height);
} completion:^(BOOL finished) {
// 延遲1s后,再利用1s的時間,讓label往上移動一段距離(回到一開始的狀態(tài))
CGFloat delay = 1.0; // 延遲1s
// UIViewAnimationOptionCurveLinear:勻速
[UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveLinear animations:^{
countLabel.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[countLabel removeFromSuperview];
}];
}];
}
@end
我的主頁
沙漠騎士