IOS 开发之UIView动画的实例详解
发布时间 - 2026-01-11 02:21:43 点击率:次IOS 动画实例详解

iOS动画的实现方式多种多样,这里就只记录一下 beginAnimations:context 。
在你调用 beginAnimations:context:方法来启动一个动画后,动画并不会立即被执行,直 到你调用 UIView 类的 commitAnimations 类方法。你对一个视图对象执行的介于 beginAnimations:context:方法跟 commitAnimations方法之间的操作(例如移动)会在 commitAnimations 被执行后才会生效 。
实现效果图:
代码很简单,直接贴了,如下:
//
// 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
以上就是关于IOS动画开发的实例,本站对于IOS 开发还有很多教程,大家可以搜索查阅!
# IOS
# UIView动画
# 动画
# UIView
# Swift 2.1 为 UIView 添加点击事件和点击效果
# IOS UIView的生命周期的实例详解
# iOS动画-定时对UIView进行翻转和抖动的方法
# IOS自定义UIView
# 在uiview 的tableView中点击cell进入跳转到另一个界面的实现方法
# iOS为UIView设置阴影效果
# IOS 开发之swift中UIView的扩展使用的实例
# 才会
# 会在
# 很简单
# 到你
# 你对
# 多种多样
# 还有很多
# 方法来
# 贴了
# implementation
# viewDidLoad
# void
# UIImageView
# import
# reserved
# interface
# nonatomic
# property
# initWithImage
# setFrame
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
用v-html解决Vue.js渲染中html标签不被解析的问题
免费的流程图制作网站有哪些,2025年教师初级职称申报网上流程?
Laravel如何构建RESTful API_Laravel标准化API接口开发指南
昵图网官网入口 昵图网素材平台官方入口
JS中使用new Date(str)创建时间对象不兼容firefox和ie的解决方法(两种)
laravel怎么使用数据库工厂(Factory)生成带有关联模型的数据_laravel Factory生成关联数据方法
Laravel如何使用Blade模板引擎?(完整语法和示例)
Windows10怎样连接蓝牙设备_Windows10蓝牙连接步骤【教程】
在线制作视频网站免费,都有哪些好的动漫网站?
详解MySQL数据库的安装与密码配置
如何在IIS中新建站点并配置端口与IP地址?
胶州企业网站制作公司,青岛石头网络科技有限公司怎么样?
青岛网站建设如何选择本地服务器?
Laravel的辅助函数有哪些_Laravel常用Helpers函数提高开发效率
js实现点击每个li节点,都弹出其文本值及修改
Laravel如何使用模型观察者?(Observer代码示例)
Laravel如何实现邮箱地址验证功能_Laravel邮件验证流程与配置
网站页面设计需要考虑到这些问题
百度浏览器网页无法复制文字怎么办 百度浏览器复制修复
如何在阿里云通过域名搭建网站?
Laravel项目怎么部署到Linux_Laravel Nginx配置详解
再谈Python中的字符串与字符编码(推荐)
如何在Windows虚拟主机上快速搭建网站?
Laravel如何实现多表关联模型定义_Laravel多对多关系及中间表数据存取【方法】
手机网站制作与建设方案,手机网站如何建设?
Android利用动画实现背景逐渐变暗
Laravel如何处理跨站请求伪造(CSRF)保护_Laravel表单安全机制与令牌校验
Laravel Vite是做什么的_Laravel前端资源打包工具Vite配置与使用
Linux系统命令中tree命令详解
如何用PHP快速搭建CMS系统?
高性能网站服务器配置指南:安全稳定与高效建站核心方案
JavaScript实现Fly Bird小游戏
Laravel如何与Docker(Sail)协同开发?(环境搭建教程)
javascript事件捕获机制【深入分析IE和DOM中的事件模型】
MySQL查询结果复制到新表的方法(更新、插入)
如何用PHP工具快速搭建高效网站?
Laravel任务队列怎么用_Laravel Queues异步处理任务提升应用性能
Laravel如何实现用户密码重置功能?(完整流程代码)
如何快速搭建高效简练网站?
如何在万网利用已有域名快速建站?
Gemini怎么用新功能实时问答_Gemini实时问答使用【步骤】
如何快速搭建高效WAP手机网站吸引移动用户?
JavaScript中的标签模板是什么_它如何扩展字符串功能
javascript读取文本节点方法小结
Win11关机界面怎么改_Win11自定义关机画面设置【工具】
Laravel如何操作JSON类型的数据库字段?(Eloquent示例)
轻松掌握MySQL函数中的last_insert_id()
图册素材网站设计制作软件,图册的导出方式有几种?
Laravel如何实现数据导出到CSV文件_Laravel原生流式输出大数据量CSV【方案】
详解免费开源的DotNet二维码操作组件ThoughtWorks.QRCode(.NET组件介绍之四)

