在navigation下方添加視圖動畫

這里我已經(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

我的主頁
沙漠騎士

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,408評論 4 61
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,111評論 25 709
  • 人啊,吃著雜碎面,唱著牧羊曲,聽著冷風(fēng)歌,想著白日夢,睡在支影床,活在后半夜! 說不出的有閑話,看不到的過昨天,笑...
    瀟雯閱讀 757評論 1 1
  • 今天分享書籍《靠譜:頂尖咨詢師教你的工作基本功》,這本書的作者大石哲之采訪了多位活躍在各個領(lǐng)域,從事過咨詢工作的人...
    李新杰2017閱讀 168評論 2 4

友情鏈接更多精彩內(nèi)容