Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >IOS 动画 动态变换背景色和大小

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

作者头像
用户5760343
发布于 2019-07-08 04:19:31
发布于 2019-07-08 04:19:31
1.3K00
代码可运行
举报
文章被收录于专栏:sktjsktj
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 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 删除。

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
IOS移动开发从入门到精通 视图UIView、层CALayer(1)
1个UIWindow 或 UIView 1、设置背景色 import UIKit class ViewController:UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. let view = UIView(frame:CGRect(x:40, y:80,width:240, height:240)) view.backgroundColor = UIColor.black view.clipsToBounds=true self.view.addSubview(view) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
用户5760343
2019/07/05
8980
IOS 弹出框
2、弹出框: import UIKit class ViewController:UIViewController { var label:UILabel! override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.brown label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = ”” self.view.addSubview(label) let button = UIButton(frame:CGRect(x:40, y:180,width:240, height:44)) button.setTitle(“打开新的视图控制器”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget(self, action:#selector(ViewController.openViewController),fo:.touchUpInside) self.view.addSubview(button) } func openViewController() { let newViewController = NewViewController() newViewController.labelTxt = “传递的参数!” newViewController.viewController = self self.present(newViewController, animated:true,completion:nil) } }
用户5760343
2019/07/07
3K0
30DaysOfSwift - Day1 计时器
前几天逛Github,偶然看到一个Swift的项目 —— 30DaysOfSwift,作者一共用30个小项目,来熟悉Swift语言,而我正好也学习了一段时间的Swift语言,准备仿照这样的模式,来更加深入的了解UI部分
Originalee
2018/08/30
9030
IOS移动开发从入门到精通 视图UIView、层CALayer(2)
或者修改 rootViewController参数 2、弹出框: import UIKit class ViewController:UIViewController { var label:UILabel! override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.brown label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = ”” self.view.addSubview(label) let button = UIButton(frame:CGRect(x:40, y:180,width:240, height:44)) button.setTitle(“打开新的视图控制器”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget(self, action:#selector(ViewController.openViewController),fo:.touchUpInside) self.view.addSubview(button) } func openViewController() { let newViewController = NewViewController() newViewController.labelTxt = “传递的参数!” newViewController.viewController = self self.present(newViewController, animated:true,completion:nil) } }
用户5760343
2019/07/05
5040
IOS 读取设备中的所有照片
1 class ViewController:UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate { 2 var imageView:UIImageView! 3 var imagePickerController:UIImagePickerController! 4 override func viewDidLoad() { 5 super.viewDidLoad() 6 // Do any additional setup after loading the view, typically from a nib. 7 8 self.imageView = UIImageView(frame:CGRect(x:20, y:120, width:280, height:200)) 9 self.view.addSubview(imageView) 10 11 let button = UIButton(frame:CGRect(x:20, y:60, width:280, height:40)) 12 button.setTitle(“选择一张图片”, for:UIControlState()) 13 button.addTarget(self, action:
用户5760343
2019/07/10
1.4K0
IOS 读取设备中的所有照片
IOS 菜单栏 UITabBarController 常用
1、创建三个视图控制器 FirstViewController、SecondViewController、ThirdViewController
用户5760343
2019/07/07
1.4K0
IOS 导航栏 UINavigationController 常用
1 创建:FirstViewController、SecondViewController 2、在FirstViewController的viewDidLoad设置属性 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. self.title = “第一页” self.view.backgroundColor = UIColor.brown self.navigationItem.rightBarButtonItem = UIBarButtonItem(title:”下一页”, style: UIBarButtonItemStyle.plain, target:self, action:
用户5760343
2019/07/07
1.2K0
IOS 给相机添加滤镜效果
1 import CoreImage 2 import AVFoundation 3 class ViewController:UIViewController,AVCaptureVideoDataOutputSampleBufferDelegate 4 var filter:CIFilter! 5 var ciImage:CIImage! 6 var videoLayer:CALayer! 7 var imageView:UIImageView! 8 var avCaptureSession:AVCaptureSession! 9 var context:CIContext = { 10 return CIContext(eaglContext:EAGLContext(api: EAGLRenderingAPI.openGLES2)!, options:nil) 11 }() 12 override func viewDidLoad() { 13 super.viewDidLoad() 14 filter = CIFilter(name:“CIPhotoEffectTransfer”) 15 buildUI() 16 buildSession() 17 } 18 func buildUI() 19 { 20 videoLayer = CALayer() 21 videoLayer.anchorPoint = CGPoint.zero 22 videoLayer.bounds = view.bounds 23 self.view.layer.insertSublayer(videoLayer, at:0) 24 25 imageView = UIImageView(frame:view.bounds) 26 self.view.addSubview(imageView) 27 28 let button = UIButton(frame:CGRect(x:0, y:420, width:320, height:60)) 29 button.setTitle(“截取图片”, for: UIControlState.init(rawValue:0)) 30 button.backgroundColor = UIColor.black 31 button.addTarget(self, action:
用户5760343
2019/07/10
1.2K0
IOS UITextField UIButton 结合
根据textfield的内容显示不同button的图像 image.png import UIKit class ViewController:UIViewController,UITextFiel
用户5760343
2019/07/08
1K0
IOS UITextField UIButton 结合
【IOS开发基础系列】UIView专题
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html
江中散人_Jun
2023/10/16
1.2K0
【IOS开发基础系列】UIView专题
Swift| 基础语法(五)
总结下 swift下的基础语法,里面涉及到:常量&变量、Swift中的数据类型、逻辑分支、循环、字符串相关、数组和字典、方法的书写调用等内容,考虑到阅读体验分多篇来展示,希望对大家学习swift有所帮助,同时也是对自己的一个总结。
進无尽
2018/09/12
2.8K0
Swift| 基础语法(五)
IOS 更简洁的动画设置方式
func playAnimation() { UIView.animate(withDuration:5, delay:0, options: [.curveEaseOut], animations:{ let view = self.view.viewWithTag(1) view?.frame = CGRect(x:40, y:40, width:0, height:0) view?.backgroundColor = UIColor.blue view?.alpha = 0 }, c
用户5760343
2019/07/08
6610
ios swift模仿qq登陆界面,xml布局
极客学院的视频:http://www.jikexueyuan.com/path/ios/
流川疯
2022/05/06
2.3K0
ios swift模仿qq登陆界面,xml布局
Swift - Button,Label
Swift-Button的常用 func setButton() { // 创建一个类型为contactAdd的按钮 let button:UIButton = UIButton(type:.contactAdd) // 设置按钮的位置和大小 button.frame = CGRect(x:10, y:150, width:100, height:30) //设置按钮文字 button.setTitle("普通按钮", for:.norm
Python疯子
2018/09/06
2K0
iOS18适配指南之UIViewController
增加了类型为UIViewController.Transition的preferredTransition属性,可以实现特殊的转场效果,共有 5 种效果,分别为zoom、coverVertical、flipHorizontal、crossDissolve与partialCurl。
YungFan
2024/09/09
5250
动画分析步骤“三步曲”
首先先来看看动画设计中的三个角色:产品设计师、算法分析师以及伟大的程序员都有哪些职责。
博文视点Broadview
2020/06/11
1.1K0
Flutter混合开发:在已有iOS项目中引入Flutter
在android项目中添加flutter模块比较简单,因为毕竟都是google的,但是在ios中添加flutter模块有些麻烦了,我们首先参考的是官方文档 https://flutter.cn/docs/development/add-to-app/ios/project-setup
BennuCTech
2022/02/25
5.2K0
Flutter混合开发:在已有iOS项目中引入Flutter
Swift纯代码构建UICollectionView
先看下效果图,很简洁,没有任何样式。 效果图 接下来就是具体的实现。 1. 创建ViewController 命名为SHomeViewController。 2. 声明 UICollectionVie
热心的程序员
2018/08/30
2K0
Swift纯代码构建UICollectionView
IOS UIWebView自己编写页面样式
1 class ViewController:UIViewController { 2 3 var webView:UIWebView! 4 override func viewDidLoad() { 5 super.viewDidLoad() 6 7 let bounds = UIScreen.main.bounds 8 let frame = CGRect(x:0, y:40, width:bounds.width, height:bounds.height-40) 9 webVie
用户5760343
2019/07/08
7290
IOS 翻页
1 import UIKit 2 3 class PageControlViewController:UIViewController, UIScrollViewDelegate { 4 5 var scrollView = UIScrollView() 6 var pageControl = UIPageControl() 7 var isPageControlUsed = false 8 override func viewDidLoad() { 9 super.viewDidLoa
用户5760343
2019/07/08
1.2K0
相关推荐
IOS移动开发从入门到精通 视图UIView、层CALayer(1)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档