在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
参考:SnapKit - 修改约束 https://blog.csdn.net/longshihua/article/details/80289061
import SnapKit class ViewController: UIViewController { private var isUpdateSnapkitV = false private lazy var snapkitV : UIView = { let snapkitV = UIView() snapkitV.backgroundColor = UIColor.red return snapkitV }() override func viewDidLoad() { super.viewDidLoad() self.view.addSubview(snapkitV) snapkitV.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(reloadView))) snapkitV.snp.makeConstraints { (make) in make.size.equalTo(CGSize(width: 100, height: 100)) make.centerX.centerY.equalTo(view) } } override func updateViewConstraints() { //移除原有的重新添加 snapkitV.snp.remakeConstraints { (make) in if isUpdateSnapkitV{ make.size.equalTo(CGSize(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.width)) }else{ make.size.equalTo(CGSize(width: 100, height: 100)) } } //更新原有的不会添加 snapkitV.snp.updateConstraints { (make) in if isUpdateSnapkitV{ make.size.equalTo(CGSize(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.width)) }else{ make.size.equalTo(CGSize(width: 100, height: 100)) } } //最后一步在调用 super.updateViewConstraints() } } extension ViewController{
|
请发表评论