ios 自訂載入動畫效果,ios自訂載入動畫

來源:互聯網
上載者:User

ios 自訂載入動畫效果,ios自訂載入動畫

在開發過程中,可能會遇到各種不同的情境需要等待載入成功後才能顯示資料。以下是自訂的一個動畫載入view效果。

    

在UIViewController的中載入等到效果,如下

- (void)viewDidLoad {    [super viewDidLoad];        //將view背景顏色變更為黃色    self.view.backgroundColor = [UIColor yellowColor];        //在self.view上載入提示框    [[BIDActivityNote sharedInstance] AddActivityView:self.view];        //延時3分鐘後移除提示框    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{        [[BIDActivityNote sharedInstance] RemoveActivityView];    });}
BIDActivityNote.h 實現代碼
////  BIDActivityNote.h//  MobileShop////  Created by eJiupi on 15-7-23.//  Copyright (c) 2014年 xujinzhong. All rights reserved.//#import <Foundation/Foundation.h>@interface BIDActivityNote : NSObject+ (BIDActivityNote*)sharedInstance;- (void)AddActivityView:(UIView*)subView;- (void)RemoveActivityView;@end

BIDActivityNote.m 代碼實現效果:

////  BIDActivityNote.m//  MobileShop////  Created by eJiupi on 15-7-23.//  Copyright (c) 2014年 xujinzhong. All rights reserved.//#import "BIDActivityNote.h"@interface BIDActivityNote ()@property (strong, nonatomic) UIView *subView;@property (strong, nonatomic) UIActivityIndicatorView *act;@end@implementation BIDActivityNote+ (BIDActivityNote*)sharedInstance{    static BIDActivityNote* instance = nil;    if (instance == nil)    {        instance = [[BIDActivityNote alloc] init];    }    return instance;}- (id)init{    self = [super init];    if (self)    {        NSInteger w = [UIScreen mainScreen].bounds.size.width;        NSInteger h = [UIScreen mainScreen].bounds.size.height;        self.subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, h)];        self.subView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];        self.act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];        //只能設定中心,不能設定大小        self.act.center = CGPointMake(w/2.f, h/2.f);        //設定活動指標的顏色        self.act.color=[UIColor whiteColor];                [self.act startAnimating]; // 開始旋轉        [self.act stopAnimating]; // 結束旋轉        //[self.act setHidesWhenStopped:YES]; //當旋轉結束時隱藏                [self.subView addSubview:self.act];    }    return self;}- (void)AddActivityView:(UIView*)subView{    //啟動    [self.act startAnimating];    [subView addSubview:self.subView];        //實現動畫效果    self.subView.transform = CGAffineTransformScale(self.subView.transform, 0, 0);    [UIView animateWithDuration:2 animations:^{        self.subView.transform = CGAffineTransformIdentity;    }]; }- (void)RemoveActivityView{    [UIView animateWithDuration:0.7 animations:^{        self.subView.transform = CGAffineTransformScale(self.subView.transform, 0, 0);    } completion:^(BOOL bfinished){        if (bfinished) {            //停止            [self.act stopAnimating];            [self.subView removeFromSuperview];        }    }];}@end


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.