You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Here is a UIViewController, mainly UIScrollView wrapped UIStackView, please note that he is the dynamic height;
if you directly display this "StackViewController" is no problem,
but because of business needs, in order to perform the jump then you need to use "UINavigationController.initWithRoot:StackViewController" , at this time can only display a fixed 44 height of the pop-up window, , look forward to fixing!
Expected behavior
display a UINavigationController with a DynamicHeightViewController
Screenshots
If applicable, add screenshots to help explain your problem.
iPhone (please complete the following information):
Device: iPhone13 Pro Max
iOS Version: iOS 17.4.1
Xcode Version 15
Dependency Manager Version [e.g. CocoaPods 1.5.2, Carthage 0.29.0]
SwiftEntryKit Release # [e.g. 0.2.0]
Additional context
import UIKit
import SnapKit
class StackViewController: UIViewController {
let scrollView = UIScrollView()
let stackView = UIStackView()
let toggleButton = UIButton()
var isHidden = false
override func viewDidLoad() {
super.viewDidLoad()
// 配置 scrollView
scrollView.backgroundColor = .yellow
view.addSubview(scrollView)
scrollView.snp.makeConstraints { make in
make.edges.equalTo(view.safeAreaLayoutGuide)
}
// 配置 stackView
stackView.axis = .vertical
stackView.distribution = .fill
stackView.spacing = 0
scrollView.addSubview(stackView)
stackView.snp.makeConstraints { make in
make.edges.equalToSuperview()
make.width.equalToSuperview()
}
// 获取屏幕高度
let screenHeight = UIScreen.main.bounds.height
// 添加子视图到 stackView
for i in 1...16 {
let subview = UILabel()
subview.text = "\(i)"
subview.tag = i // 为每个子视图设置 tag 以便识别
subview.backgroundColor = i % 2 == 0 ? .red : .blue // 交替颜色便于区分
stackView.addArrangedSubview(subview)
// 设置高度约束
subview.snp.makeConstraints { make in
make.height.equalTo(screenHeight / 10).priority(.required)
}
}
// 配置按钮
toggleButton.setTitle("Toggle Odd Rows", for: .normal)
toggleButton.backgroundColor = .systemBlue
toggleButton.addTarget(self, action: #selector(toggleOddRows), for: .touchUpInside)
view.addSubview(toggleButton)
toggleButton.snp.makeConstraints { make in
make.bottom.equalTo(view.safeAreaLayoutGuide).offset(-20)
make.centerX.equalToSuperview()
make.width.equalTo(200)
make.height.equalTo(50)
}
}
@objc func toggleOddRows() {
isHidden.toggle()
UIView.animate(withDuration: 0.5, animations: {
for i in 1...16 {
if let subview = self.stackView.viewWithTag(i) {
if i % 2 != 0 { // 单数行
subview.isHidden = self.isHidden
}
}
}
self.stackView.layoutIfNeeded() // 强制刷新 stackView 布局
}) { _ in
// 更新 scrollView 内容高度
self.scrollView.setNeedsLayout()
self.scrollView.layoutIfNeeded()
}
}
Describe the bug
Here is a UIViewController, mainly UIScrollView wrapped UIStackView, please note that he is the dynamic height;
if you directly display this "StackViewController" is no problem,
but because of business needs, in order to perform the jump then you need to use "UINavigationController.initWithRoot:StackViewController" , at this time can only display a fixed 44 height of the pop-up window, , look forward to fixing!
Expected behavior
display a UINavigationController with a DynamicHeightViewController
Screenshots
If applicable, add screenshots to help explain your problem.
iPhone (please complete the following information):
Additional context
import UIKit
import SnapKit
class StackViewController: UIViewController {
}
===============
Screenshots / Video Links
The text was updated successfully, but these errors were encountered: