如何解决设置stackView时发生内存泄漏-Swift-以编程方式
我正在设置一个底部按钮StackView,但我发现,只要设置它,我就会发现内存使用立即增加。
这是我在viewDidLoad()中实现的用于设置底部stackView的代码:
@objc fileprivate func setUPUI(){
let buttonsstackview = UIStackView(arrangedSubviews: [acceptButton,detailButton,cancelButton])
buttonsstackview.axis = .horizontal
buttonsstackview.distribution = .equalSpacing
buttonsstackview.alignment = .center
buttonsstackview.spacing = 20
//defining buttons Constraints
acceptButton.heightAnchor.constraint(equalToConstant: sideViewsSize).isActive = true
acceptButton.widthAnchor.constraint(equalToConstant: sideViewsSize).isActive = true
detailButton.heightAnchor.constraint(equalToConstant: centerViewSize).isActive = true
detailButton.widthAnchor.constraint(equalToConstant: centerViewSize).isActive = true
cancelButton.heightAnchor.constraint(equalToConstant: sideViewsSize).isActive = true
cancelButton.widthAnchor.constraint(equalToConstant: sideViewsSize).isActive = true
//setting shadows
acceptButton.setupShadow(opacity: 0.7,radius: 4,offset: .init(width: 0,height: 0),color: .darkGray)
detailButton.setupShadow(opacity: 0.7,color: .darkGray)
cancelButton.setupShadow(opacity: 0.7,color: .darkGray)
buttonsstackview.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(buttonsstackview)
buttonsstackview.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor,constant: -5).isActive = true
buttonsstackview.heightAnchor.constraint(equalToConstant: 90).isActive = true
buttonsstackview.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
buttonsstackview.leadingAnchor.constraint(greaterThanorEqualTo: view.leadingAnchor,constant: 20).isActive = true
buttonsstackview.trailingAnchor.constraint(lessthanorEqualTo: view.trailingAnchor,constant: -20).isActive = true
}
当我加载viewController时,它从41MB变为296MB
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。