《慕客网:IOS-动画入门》学习笔记

本文介绍如何使用Swift在iOS应用中创建一个简单的UIView动画效果,包括UIView的基本操作及动画实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

新建Cocoa Touch Class,语言是swift

然后继续为界面添加一个普通的View Controller,并且添加前面视图的静态table的转向剪头指向这个View Controller,然后在这个视图上添加普通的UIView

 

 
 1 class PositionViewController: UIViewController {
 2 
 3     //2 添加 UIView组件 的链接
 4     @IBOutlet weak var redSquare: UIView!
 5     
 6     override func viewDidLoad() {
 7         super.viewDidLoad()
 8 
 9         // Do any additional setup after loading the view.
10     }
11 
12     override func didReceiveMemoryWarning() {
13         super.didReceiveMemoryWarning()
14         // Dispose of any resources that can be recreated.
15     }
16     //1
17     override func viewDidAppear(animated: Bool) {
18         //这个方法被执行的时间在生命周期中比较合适
19         UIView.animateWithDuration(1, animations: {
20             self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
21         })
22         UIView.animateWithDuration(1, delay: 2, options: nil, animations: {
23             self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
24             self.redSquare.center.y = self.view.bounds.height - self.redSquare.center.y
25         }, completion: nil)
26     }
27     
28 
29     /*
30     // MARK: - Navigation
31 
32     // In a storyboard-based application, you will often want to do a little preparation before navigation
33     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
34         // Get the new view controller using segue.destinationViewController.
35         // Pass the selected object to the new view controller.
36     }
37     */
38 
39 }

 

前面都是大致的简单的入门步骤,不管是什么类型的动画的方法,比如下面的透明度变化动画:
animations的闭包类型的参数所包含的方法就是 在设定时间内变化到达的目标值,比如这个透明度动画设置为目标透明度为alpha=0.2,比如上面简单实例里的位移动画设置为目标位置。
比较好的动画源代码的下载百度网址:
链接: http://pan.baidu.com/s/1jGnIC2U 密码: x4cy
 
 github网址:https://codeload.github.com/JakeLin/iOSAnimationSample/zip/master
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值