IOS 開發(fā)之UIView動畫的實例詳解
IOS 動畫實例詳解
iOS動畫的實現(xiàn)方式多種多樣,這里就只記錄一下 beginAnimations:context 。
在你調(diào)用 beginAnimations:context:方法來啟動一個動畫后,動畫并不會立即被執(zhí)行,直 到你調(diào)用 UIView 類的 commitAnimations 類方法。你對一個視圖對象執(zhí)行的介于 beginAnimations:context:方法跟 commitAnimations方法之間的操作(例如移動)會在 commitAnimations 被執(zhí)行后才會生效 。
實現(xiàn)效果圖:
代碼很簡單,直接貼了,如下:
// // ViewController.m // Graphics // // Created by aaron on 14b-5-29. // Copyright (c) 2014年 The Technology Studio. All rights reserved. // #import "ViewController.h" @interface ViewController () @property(nonatomic,strong) UIImageView *imageView1; @property(nonatomic,strong) UIImageView *imageView2; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIImage *image = [UIImage imageNamed:@"1.png"]; self.imageView1 = [[UIImageView alloc] initWithImage:image]; self.imageView2 = [[UIImageView alloc] initWithImage:image]; [self.imageView1 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; [self.imageView2 setFrame:CGRectMake(220.0f, 350.0f, 100.0f, 100.0f)]; [self.view addSubview:self.imageView1]; [self.view addSubview:self.imageView2]; // [self startTopLeftImageViewAnimation]; // [self startBottomRightViewAnimationAfterDelay:2]; [self affineTransformScaleAnimation]; [self affineTransformRotateAnimation]; } //imageView2 animation -(void)startTopLeftImageViewAnimation{ [self.imageView1 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; [self.imageView1 setAlpha:1.0f]; [UIView beginAnimations:@"imageView1Animation" context:(__bridge void*)self.imageView1]; [UIView setAnimationDuration:3.0f]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)]; [self.imageView1 setFrame:CGRectMake(220.0f, 350.0f, 100.0f, 100.0f)]; [self.imageView1 setAlpha:0.0f]; [UIView commitAnimations]; } -(void)imageViewDidStop:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{ NSLog(@"AnimationID = %@\n",paramAnimationID); UIImageView *contextImageView = (__bridge UIImageView *)(paramContext); NSLog(@"contextImageView = %@",contextImageView); [contextImageView removeFromSuperview]; } //imageView2 animation -(void)startBottomRightViewAnimationAfterDelay:(CGFloat)paramDelay{ [self.imageView2 setFrame:CGRectMake(220.0f, 350.0f, 100.0f, 100.0f)]; [self.imageView2 setAlpha:1.0f]; [UIView beginAnimations:@"imageView2Animation" context:(__bridge voidvoid *)(self.imageView2)]; [UIView setAnimationDuration:3.0f]; [UIView setAnimationDelay:paramDelay]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)]; [self.imageView2 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; [self.imageView2 setAlpha:0.0f]; [UIView commitAnimations]; } //imageView1 AffineTransformScale animation -(void)affineTransformScaleAnimation{ self.imageView1.center = self.view.center; self.imageView1.transform = CGAffineTransformIdentity; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:5.0f]; self.imageView1.transform = CGAffineTransformMakeScale(2.0f, 2.0f); [self.imageView1 setAlpha:0.0f]; [UIView commitAnimations]; } //imageView2 AffineTransformRotate animation -(void)affineTransformRotateAnimation{ self.imageView2.center = self.view.center; [UIView beginAnimations:@"clockwiseAnimation" context:NULL]; [UIView setAnimationDuration:5.0f]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(clockwiseRotationStopped:finished:context:)]; self.imageView2.transform = CGAffineTransformMakeRotation(90.0f*M_PI/180.f); [UIView commitAnimations]; } -(void)clockwiseRotationStopped:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{ [UIView beginAnimations:@"counterclockwiseAnimation" context:NULL]; [UIView setAnimationDuration:5.0f]; self.imageView2.transform = CGAffineTransformIdentity; [UIView commitAnimations]; } @end
以上就是關(guān)于IOS動畫開發(fā)的實例,本站對于IOS 開發(fā)還有很多教程,大家可以搜索查閱!
相關(guān)文章
詳解iOS學習筆記(十七)——文件操作(NSFileManager)
這篇文章主要介紹了詳解iOS學習筆記(十七)——文件操作(NSFileManager),具有一定的參考價值,有需要的可以了解一下。2016-12-12IOS 播放系統(tǒng)提示音使用總結(jié)(AudioToolbox)
這篇文章主要介紹了IOS 播放系統(tǒng)提示音使用總結(jié)(AudioToolbox)的相關(guān)資料,需要的朋友可以參考下2017-05-05iOS程序開發(fā)中設(shè)置UITableView的全屏分隔線的方法(不畫線)
ableView是app開發(fā)中常用到的控件,功能很強大,多用于數(shù)據(jù)的顯示。下面給大家介紹設(shè)置UITableView的全屏分隔線的兩種方法2016-04-04Swift實現(xiàn)iOS應(yīng)用中短信驗證碼倒計時功能的實例分享
這篇文章主要介紹了Swift實現(xiàn)iOS應(yīng)用中短信驗證碼倒計時功能的實例分享,開啟和關(guān)閉倒計時功能的步驟實現(xiàn)比較關(guān)鍵,需要的朋友可以參考下2016-04-04淺談關(guān)于如何檢測iOS14本地網(wǎng)絡(luò)權(quán)限的一些思路
這篇文章主要介紹了淺談關(guān)于如何檢測iOS14本地網(wǎng)絡(luò)權(quán)限的一些思路,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-09-09