慕函数2162820
闭包就相当于OC种的Block,可以用来返回,也可以用来传参,多练习练习就能明白其中的意义了
BeBeBerr3477889
import UIKit
import XCPlayground
import PlaygroundSupport
var wrap = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300));
var rect = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50));
rect.center = wrap.center;
rect.backgroundColor = UIColor.red;
wrap.addSubview(rect);
//animation
UIView.animate(withDuration: 3){
rect.backgroundColor = UIColor.green;
rect.frame = wrap.frame;
};
//XCPlaygroundPage.currentPage.liveView=wrap;
PlaygroundPage.current.liveView=wrap;