iOS动画入门
2015-07-08 19:03
393 查看
一 动画介绍
在iOS中动画实现技术主要是:Core Animation。 Core Animation负责所有的滚动、旋转、缩小和放大以及所有的iOS动画效果。其中UIKit类通常都有animated:参数部分,它可以允许是否使用动画。本文将介绍UIView动画的实现方式,有基础方法和block方法。
二 实现方法
1 基础动画
[objc] viewplaincopy
[UIView beginAnimations:nil context:nil]; //动画开始
//Code...
[UIView commitAnimations]; //动画结束
[objc] view
plaincopy
//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
[objc] viewplaincopy
[UIView animateWithDuration:3 //动画持续时间
animations:^{
//Code...
}];
[objc] view
plaincopy
//eg 改变lb的透明度
[UIView animateWithDuration:3 animations:^{
self.lb.alpha = 0.5;
}];
3 blcok方法2
[objc] viewplaincopy
UIView animateWithDuration:3 //动画持续时间
animations:^{
//动画执行
} completion:^(BOOL finished) {
//动画完成后执行
}];
[objc] view
plaincopy
//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
[objc] viewplaincopy
[UIView animateWithDuration:3 //动画持续时间
delay:1 //动画延迟时间
options:UIViewAnimationOptionCurveEaseIn //设置动画过渡效果
animations:^{
//动画执行
} completion:^(BOOL finished) {
//动画完成后执行
}];
[objc] view
plaincopy
//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
[objc] viewplaincopy
[UIView animateWithDuration:3 //动画持续时间
delay:1 //动画延迟时间
usingSpringWithDamping:1.0 //设置类似弹簧效果
initialSpringVelocity:5.0 //设置初始速度
options:UIViewAnimationOptionCurveLinear //设置动画过渡效果
animations:^{
} completion:^(BOOL finished) {
}];
[objc] view
plaincopy
[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 = @"弹簧效果结束";
}];
相关文章推荐
- iOS蓝牙4.0入门
- 2015年7月8日
- iOS多线程入门之NSThread,NSOperation,GCD
- [ 转] 漫谈iOS Crash收集框架
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- iOS开发如何提高(from 唐巧的博客)
- ios keyboard 虚拟键盘 删除键的判断
- iOSAutoLayout自动布局中级开发教程(4)label等文字自动适应大小 宽度
- IOS页面加载Html5页面
- iOS开发系列--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook详解
- ios 资源
- iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用
- iOS--坐标变换Quartz 2D中的CGContextTranslateCTM、CGContextScaleCTM、CGContextRotateCTM、CGContextConcatCTM等
- IOS应用程序的5中状态
- [Phonegap+Sencha Touch] 移动开发5、Sencha touch结合Phonegap使用
- iOS8 下定位失败问题
- IOS - 注册手机号和重置密码请求函数
- IOS 版本升级思路
- iOS-百度地图_屏幕所显示范围内的经纬度
- IOS 版本号大小比较