您的位置:首页 > 移动开发 > IOS开发

iOS动画入门

2015-07-08 19:03 393 查看


一 动画介绍

在iOS中动画实现技术主要是:Core Animation。 Core Animation负责所有的滚动、旋转、缩小和放大以及所有的iOS动画效果。其中UIKit类通常都有animated:参数部分,它可以允许是否使用动画。

本文将介绍UIView动画的实现方式,有基础方法和block方法。


二 实现方法


1 基础动画

[objc] view
plaincopy

[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] view
plaincopy

[UIView animateWithDuration:3 //动画持续时间

animations:^{

//Code...

}];

[objc] view
plaincopy

//eg 改变lb的透明度

[UIView animateWithDuration:3 animations:^{

self.lb.alpha = 0.5;

}];


3 blcok方法2

[objc] view
plaincopy

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] view
plaincopy

[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] view
plaincopy

[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 = @"弹簧效果结束";

}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: