为了账号安全,请及时绑定邮箱和手机立即绑定

Playground简单色条动画

标签:
iOS
import UIKit
import XCPlayground

let showView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
showView.backgroundColor = UIColor.black

let rectangle1 = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
let rectangle2 = UIView(frame: CGRect(x: 0, y: 50, width: 50, height: 50))
let rectangle3 = UIView(frame: CGRect(x: 0, y: 100, width: 50, height: 50))
let rectangle4 = UIView(frame: CGRect(x: 0, y: 150, width: 50, height: 50))
let rectangle5 = UIView(frame: CGRect(x: 0, y: 200, width: 50, height: 50))
let rectangle6 = UIView(frame: CGRect(x: 0, y: 250, width: 50, height: 50))

rectangle1.backgroundColor = UIColor.red
rectangle2.backgroundColor = UIColor.orange
rectangle3.backgroundColor = UIColor.yellow
rectangle4.backgroundColor = UIColor.green
rectangle5.backgroundColor = UIColor.blue
rectangle6.backgroundColor = UIColor.purple
showView.addSubview(rectangle6)
showView.addSubview(rectangle5)
showView.addSubview(rectangle4)
showView.addSubview(rectangle3)
showView.addSubview(rectangle2)
showView.addSubview(rectangle1)

UIView.animate(withDuration: 2){
    rectangle1.backgroundColor = UIColor.purple
    rectangle1.frame = CGRect(x: 250, y: 50, width: 50, height: 150)
    rectangle2.backgroundColor = UIColor.blue
    rectangle2.frame = CGRect(x: 200, y: 100, width: 50, height: 150)
    rectangle3.backgroundColor = UIColor.green
    rectangle3.frame = CGRect(x: 150, y: 50, width: 50, height: 150)
    rectangle4.backgroundColor = UIColor.yellow
    rectangle4.frame = CGRect(x: 100, y: 100, width: 50, height: 150)
    rectangle5.backgroundColor = UIColor.orange
    rectangle5.frame = CGRect(x: 50, y: 50, width: 50, height: 150)
    rectangle6.backgroundColor = UIColor.red
    rectangle6.frame = CGRect(x: 0, y: 100, width: 50, height: 150)
}

XCPlaygroundPage.currentPage.liveView = showView
点击查看更多内容
2人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消