谈UIView Animation编程艺术

原文链接:http://www.jianshu.com/p/51ce7966a038

一.大小动画(改变frame)


1.展示效果


2.Show Code


-(void)changeFrame{

CGRect originalRect = self.anView.frame;

CGRect rect = CGRectMake(self.anView.frame.origin.x-20, self.anView.frame.origin.y-120, 160, 80);

[UIView animateWithDuration:1 animations:^{

self.anView.frame = rect;

} completion:^(BOOL finished) {

[UIView animateWithDuration:1 animations:^{

self.anView.frame = originalRect;

}];

}];

}


二.拉伸动画(改变bounds)


1.展示效果


bounds变化


2.Show Code


-(void)changeBounds{

CGRect originalBounds = self.anView.bounds;

//尽管这个rect的x,y跟原始的不同,动画也只是改变了宽高

CGRect rect = CGRectMake(0, 0, 300, 120);

[UIView animateWithDuration:1 animations:^{

self.anView.bounds = rect;

} completion:^(BOOL finished) {

[UIView animateWithDuration:1 animations:^{

self.anView.bounds = originalBounds;

}];

}];

}


三.转移动画(改变center)


1.展示效果


center变化.gif


2.Show Code


-(void)changeCenter{

CGPoint originalPoint = self.anView.center;

CGPoint point = CGPointMake(self.anView.center.x, self.anView.center.y-170);

[UIView animateWithDuration:0.3 animations:^{

self.anView.center = point;

} completion:^(BOOL finished) {

[UIView animateWithDuration:1 animations:^{

self.anView.center = originalPoint;

}];

}];

}


谢谢二爷的示范,经典的表情也勾起很多人的回忆。好,我们回到现实,以上的3个例子,大家不难发现共同的特点和重复性。


1.都是改变UIView的属性就可以产生动画。

2.都是带有block做结束回调,对结束监控

3.动画大小和位置变化可以通过多种方式实现


“佛爷,是不是很好奇我们并没有使用Tom先生很多图片组逐一显示?来,也请您下矿一走!”。“哈哈,好!不过那碗河水我还是要倒的”,“行,随你翻腾~”。


四.旋转动画(改变transform)


1.展示效果

transform变化.gif


2.Show Code


-(void)transform{

CGAffineTransform originalTransform = self.anView.transform;

[UIView animateWithDuration:2 animations:^{

//self.anView.transform = CGAffineTransformMakeScale(0.6, 0.6);//缩放

//self.anView.transform = CGAffineTransformMakeTranslation(60, -60);

self.anView.transform = CGAffineTransformMakeRotation(4.0f);

} completion:^(BOOL finished) {

[UIView animateWithDuration:2 animations:^{

self.anView.transform = originalTransform;

}];

}];

}


五.透明度动画(改变alpha)


1.展示效果


alpha变化.gif


2.Show Code


-(void)alpha{

[UIView animateWithDuration:2 animations:^{

self.anView.alpha = 0.3;

} completion:^(BOOL finished) {

[UIView animateWithDuration:2 animations:^{

self.anView.alpha = 1;

}];

}];

}


卓先生,停停停,来,回到我们舞台中间来。就以上5中都能让您玩的这么愉快,以上都是仅仅修改本身的属性值,我再介绍剩下三种基于UIView特别的动画,一个是Keyframe,一个Spring和Transition动画。一人一个轮着来,卓先生你先。


六.背景颜色Keyframes动画(改变background)


1.展示效果

background变化.gif


2.Show Code


-(void)changeBackground{

[UIView animateKeyframesWithDuration:9.0 delay:0.f options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{

[UIView addKeyframeWithRelativeStartTime:0.f relativeDuration:1.0 / 4 animations:^{

self.anView.backgroundColor = [UIColor colorWithRed:0.9475 green:0.1921 blue:0.1746 alpha:1.0];

}];

[UIView addKeyframeWithRelativeStartTime:1.0 / 4 relativeDuration:1.0 / 4 animations:^{

self.anView.backgroundColor = [UIColor colorWithRed:0.1064 green:0.6052 blue:0.0334 alpha:1.0];

}];

[UIView addKeyframeWithRelativeStartTime:2.0 / 4 relativeDuration:1.0 / 4 animations:^{

self.anView.backgroundColor = [UIColor colorWithRed:0.1366 green:0.3017 blue:0.8411 alpha:1.0];

}];

[UIView addKeyframeWithRelativeStartTime:3.0 / 4 relativeDuration:1.0 / 4 animations:^{

self.anView.backgroundColor = [UIColor colorWithRed:0.619 green:0.037 blue:0.6719 alpha:1.0];

}];

[UIView addKeyframeWithRelativeStartTime:3.0 / 4 relativeDuration:1.0 / 4 animations:^{

self.anView.backgroundColor = [UIColor whiteColor];

}];

} completion:^(BOOL finished) {

NSLog(@"动画结束");

}];

}


七.Spring动画(iOS7.0起)


1.展示效果


spring动画.gif


2.Show Code


-(void)springAnimation{

CGRect originalRect = self.anView.frame;

CGRect rect = CGRectMake(self.anView.frame.origin.x-80, self.anView.frame.origin.y, 120, 120);

[UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:4 options:UIViewAnimationOptionCurveLinear animations:^{

self.anView.frame = rect;

} completion:^(BOOL finished) {

[UIView animateWithDuration:1 delay:1 usingSpringWithDamping:0.5 initialSpringVelocity:4 options:UIViewAnimationOptionCurveLinear animations:^{

self.anView.frame = originalRect;

} completion:^(BOOL finished) {

}];

}];

}


八.transition动画


1.展示效果

transition动画.gif


2.Show Code


-(void)transitionAnimation{

[UIView transitionWithView:self.anView duration:2.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{

//self.anView.backgroundColor = [UIColor blueColor];

} completion:^(BOOL finished) {

[UIView transitionWithView:self.anView duration:2.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{

//self.anView.backgroundColor = [UIColor greenColor];

} completion:^(BOOL finished) {

}];

}];

}


九.关于参数option选择说明


1.UIViewAnimationOptions


UIViewAnimationOptionLayoutSubviews            //进行动画时布局子控件

UIViewAnimationOptionAllowUserInteraction      //进行动画时允许用户交互

UIViewAnimationOptionBeginFromCurrentState     //从当前状态开始动画

UIViewAnimationOptionRepeat                    //无限重复执行动画

UIViewAnimationOptionAutoreverse               //执行动画回路

UIViewAnimationOptionOverrideInheritedDuration //忽略嵌套动画的执行时间设置

UIViewAnimationOptionOverrideInheritedCurve    //忽略嵌套动画的曲线设置

UIViewAnimationOptionAllowAnimatedContent      //转场:进行动画时重绘视图

UIViewAnimationOptionShowHideTransitionViews   //转场:移除(添加和移除图层的)动画效果

UIViewAnimationOptionOverrideInheritedOptions  //不继承父动画设置

UIViewAnimationOptionCurveEaseInOut            //时间曲线,慢进慢出(默认值)

UIViewAnimationOptionCurveEaseIn               //时间曲线,慢进

UIViewAnimationOptionCurveEaseOut              //时间曲线,慢出

UIViewAnimationOptionCurveLinear               //时间曲线,匀速

UIViewAnimationOptionTransitionNone            //转场,不使用动画

UIViewAnimationOptionTransitionFlipFromLeft    //转场,从左向右旋转翻页

UIViewAnimationOptionTransitionFlipFromRight   //转场,从右向左旋转翻页

UIViewAnimationOptionTransitionCurlUp          //转场,下往上卷曲翻页

UIViewAnimationOptionTransitionCurlDown        //转场,从上往下卷曲翻页

UIViewAnimationOptionTransitionCrossDissolve   //转场,交叉消失和出现

UIViewAnimationOptionTransitionFlipFromTop     //转场,从上向下旋转翻页

UIViewAnimationOptionTransitionFlipFromBottom  //转场,从下向上旋转翻页


2.UIViewKeyframeAnimationOptions


UIViewAnimationOptionLayoutSubviews           //进行动画时布局子控件

UIViewAnimationOptionAllowUserInteraction     //进行动画时允许用户交互

UIViewAnimationOptionBeginFromCurrentState    //从当前状态开始动画

UIViewAnimationOptionRepeat                   //无限重复执行动画

UIViewAnimationOptionAutoreverse              //执行动画回路

UIViewAnimationOptionOverrideInheritedDuration //忽略嵌套动画的执行时间设置

UIViewAnimationOptionOverrideInheritedOptions //不继承父动画设置

UIViewKeyframeAnimationOptionCalculationModeLinear     //运算模式 :连续

UIViewKeyframeAnimationOptionCalculationModeDiscrete   //运算模式 :离散

UIViewKeyframeAnimationOptionCalculationModePaced      //运算模式 :均匀执行

UIViewKeyframeAnimationOptionCalculationModeCubic      //运算模式 :平滑

UIViewKeyframeAnimationOptionCalculationModeCubicPaced //运算模式 :平滑均匀


就UIView的动画而言,UIViewKeyframeAnimationOptions紧在Keyframes,其余的都是UIViewAnimationOptions。


十.总结和扩展


1.UIView动画主要是变化UIView的自带属性

2.UIView动画可以有很多种方式实现同一效果

3.Spring动画iOS7.0以上才有

4.UIViewKeyframeAnimationOptions用着Keyframes动画,其余都用UIViewAnimationOptions枚举

《餐馆点餐管理系统——基于Java和MySQL的课程设计解析》 在信息技术日益发达的今天,餐饮行业的数字化管理已经成为一种趋势。本次课程设计的主题是“餐馆点餐管理系统”,它结合了编程语言Java和数据库管理系统MySQL,旨在帮助初学者理解如何构建一个实际的、具有基本功能的餐饮管理软件。下面,我们将深入探讨这个系统的实现细节及其所涉及的关键知识点。 我们要关注的是数据库设计。在“res_db.sql”文件中,我们可以看到数据库的结构,可能包括菜品表、订单表、顾客信息表等。在MySQL中,我们需要创建这些表格并定义相应的字段,如菜品ID、名称、价格、库存等。此外,还要设置主键、外键来保证数据的一致性和完整性。例如,菜品ID作为主键,确保每个菜品的唯一性;订单表中的顾客ID和菜品ID则作为外键,与顾客信息表和菜品表关联,形成数据间的联系。 接下来,我们来看Java部分。在这个系统中,Java主要负责前端界面的展示和后端逻辑的处理。使用Java Swing或JavaFX库可以创建用户友好的图形用户界面(GUI),让顾客能够方便地浏览菜单、下单。同时,Java还负责与MySQL数据库进行交互,通过JDBC(Java Database Connectivity)API实现数据的增删查改操作。在程序中,我们需要编写SQL语句,比如INSERT用于添加新的菜品信息,SELECT用于查询所有菜品,UPDATE用于更新菜品的价格,DELETE用于删除不再提供的菜品。 在系统设计中,我们还需要考虑一些关键功能的实现。例如,“新增菜品和价格”的功能,需要用户输入菜品信息,然后通过Java程序将这些信息存储到数据库中。在显示所有菜品的功能上,程序需要从数据库获取所有菜品数据,然后在界面上动态生成列表或者表格展示。同时,为了提高用户体验,可能还需要实现搜索和排序功能,允许用户根据菜品名称或价格进行筛选。 另外,安全性也是系统设计的重要一环。在连接数据库时,要避免SQL注入攻击,可以通过预编译的PreparedStatement对象来执行SQL命令。对于用户输入的数据,需要进行验证和过滤,防止非法字符和异常值。 这个“餐馆点餐管理系统”项目涵盖了Java编程、数据库设计与管理、用户界面设计等多个方面,是一个很好的学习实践平台。通过这个项目,初学者不仅可以提升编程技能,还能对数据库管理和软件工程有更深入的理解。在实际开发过程中,还会遇到调试、测试、优化等挑战,这些都是成长为专业开发者不可或缺的经验积累
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值