继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Playground简单色条动画2

SpearLonginus
关注TA
已关注
手记 2
粉丝 0
获赞 4
import UIKit
import XCPlayground

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

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

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

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

XCPlaygroundPage.currentPage.liveView = showView
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP