iOS動畫入門一,iOS動畫入門

來源:互聯網
上載者:User

iOS動畫入門一,iOS動畫入門
 一 動畫介紹

在iOS中動畫實現技術主要是:Core Animation。 Core Animation負責所有的滾動、旋轉、縮小和放大以及所有的iOS動畫效果。其中UIKit類通常都有animated:參數部分,它可以允許是否使用動畫。 

本文將介紹UIView動畫的實現方式,有基礎方法和block方法。

二 實現方法1 基礎動畫

 [UIView  beginAnimations:nil context:nil];  //動畫開始    //Code... [UIView commitAnimations];                  //動畫結束

    //eg 設定lb向下移動    [UIView beginAnimations:nil context:nil];    [UIView setAnimationDuration:3];    CGPoint point = self.lb.center;    point.y += 100;    self.lb.center = point;    [UIView commitAnimations];

2 blcok方法1

 [UIView animateWithDuration:3   //動畫期間                     animations:^{        //Code...    }];

//eg 改變lb的透明度    [UIView animateWithDuration:3 animations:^{        self.lb.alpha = 0.5;    }];

3 blcok方法2

UIView animateWithDuration:3   //動畫期間                     animations:^{        //動畫執行    } completion:^(BOOL finished) {        //動畫完成後執行    }];

//eg 旋轉lb第一種方法:    CGAffineTransform endAngel = CGAffineTransformMakeRotation(90.0f*(M_PI/180.0f));        [UIView animateWithDuration:3 animations:^{        self.lb.transform = endAngel;    } completion:^(BOOL finished) {        self.stateLb.text = @"動畫完成了";    }];


4 blcok方法3

[UIView animateWithDuration:3   //動畫期間                          delay:1   //動畫延遲時間                        options:UIViewAnimationOptionCurveEaseIn    //設定動畫過渡效果                     animations:^{        //動畫執行    } completion:^(BOOL finished) {        //動畫完成後執行    }];

 //eg 改變lb的字型大小 和位置    [UIView animateWithDuration:3                          delay:1                        options:UIViewAnimationOptionCurveEaseInOut //設定動畫過渡效果                     animations:^{        CGPoint center = self.lb.center;        center.x = 200;        self.lb.center = center;                self.lb.textColor = [UIColor blueColor];    } completion:^(BOOL finished) {        self.stateLb.text = @"改變lb的字型大小 和位置 完成*";    }];



5 blcok方法4

[UIView animateWithDuration:3       //動畫期間                          delay:1       //動畫延遲時間         usingSpringWithDamping:1.0     //設定類似彈簧效果          initialSpringVelocity:5.0     //設定初始速度                        options:UIViewAnimationOptionCurveLinear //設定動畫過渡效果                     animations:^{        } completion:^(BOOL finished) {            }];

[UIView animateWithDuration:3 delay:1 usingSpringWithDamping:1.0 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{        CGPoint center = self.btn.center;        center.y += 50;        self.btn.center = center;    } completion:^(BOOL finished) {        self.stateLb.text = @"彈簧效果結束";    }];



著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.