前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IOS 动画 动态变换背景色和大小

IOS 动画 动态变换背景色和大小

作者头像
用户5760343
发布2019-07-08 12:19:31
1.2K0
发布2019-07-08 12:19:31
举报
文章被收录于专栏:sktj
代码语言:javascript
复制
 1 import UIKit
 2
 3 class ViewController:UIViewController {
 4
 5 override func viewDidLoad() {
 6 super.viewDidLoad()
 7 // Do any additional setup after loading the view,
 typically from a nib.
 8 let rect = CGRect(x:40, y:80, width:240, height:
 
 9 let view = UIView(frame:rect)
 10 view.backgroundColor = UIColor.red
 11 view.tag = 1
 12 self.view.addSubview(view)
 13
 14 let button = UIButton(type:UIButtonType.System)
 15 button.frame = CGRect(x:50, y:400, width:220,
 height:44)
 16 button.backgroundColor = UIColor.black
 17 button.setTitle(“Play”, for:UIControlState())
 18 button.addTarget(self, action:
selector(ViewController.playAnimation), for:
UIControlEvents.touchUpInside)
 19 self.view.addSubview(button)
 20 }
 21
 22 func playAnimation()
 23 {
 24 UIView.beginAnimations(nil, context:nil)
 25 UIView.setAnimationCurve(.easeOut)
 26 UIView.setAnimationDuration(5)
 27 UIView.setAnimationBeginsFromCurrentState(true)
 28
 29 let view = self.view.viewWithTag(1)
 30 view?.frame = CGRect(x:40, y:40, width:0,
 height:0)
 31 view?.backgroundColor = UIColor.blue
 32 view?.alpha = 0
 33
 34 UIView.setAnimationDelegate(self)
 35
 UIView.setAnimationDidStop(#selector(ViewController.animationStop))
 36 UIView.commitAnimations()
 37 }
 38
 39 func animationStop()
 40 {
 41 print(“Animaton stop.”)
 42 self.view.viewWithTag(1)?.removeFromSuperview()
 43 }
 44
 45 override func didReceiveMemoryWarning() {
 46 super.didReceiveMemoryWarning()
 47 // Dispose of any resources that can be recreated.
 48 }
 49 }
//动画类型:速度类型

image.png

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.06.10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档