ios 渐变动画

来源:互联网 发布:手机版淘宝投诉卖家 编辑:程序博客网 时间:2024/05/17 20:28

// 方式一
// 1.开始动画
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0]; // 设置动画时长
// 1.动画代码,动画执行内容
CGRect frame = self.orangeView.frame; // frame不能被直接修改,必须创建一份
frame.origin.x += 10; // x轴移动10 个像素
self.orangeView.frame = frame;
// 提交动画
[UIView commitAnimations];

——— IOS的动画一般是这种方式,[UIView animateWithxx ,然后在里面改变控件属性即可
// 方式二
[UIView animateWithDuration:1.0 animations:^{
// 动画代码
CGRect frame = self.orangeView.frame; //注意:这里不能直接设置frame
frame.origin.x += 40;
self.orangeView.frame = frame;
}];

// 方式三
[UIView animateWithDuration:1.0 animations:^{
// 执行动画
CGRect frame = self.orangeView.frame;
frame.origin.x += 40;
self.orangeView.frame = frame;
} completion:^(BOOL finished) {
// 动画完成做什么事情
self.orangeView.backgroundColor = [UIColor blueColor];
}];

// 方式四
// UIViewAnimationOptionCurveEaseInOut 缓入缓出
// UIViewAnimationOptionCurveEaseIn 缓入
// UIViewAnimationOptionCurveEaseOut 缓出
// UIViewAnimationOptionCurveLinear 线性
// delay: 延时执行
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
// 执行动画
CGRect frame = self.orangeView.frame;
frame.origin.x += 100;
self.orangeView.frame = frame;
} completion:^(BOOL finished) {
// 动画完成做什么事情
self.orangeView.backgroundColor = [UIColor blackColor];
}];

如果是要实现控件的选择,要使用transform属性

作者:冷洪林
链接:http://www.jianshu.com/p/8f16f94f6362
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。