Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新布局问题 #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Sources/Core/JXSegmentedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ open class JXSegmentedView: UIView, JXSegmentedViewRTLCompatible {
if isFirstLayoutSubviews {
isFirstLayoutSubviews = false
collectionView.frame = targetFrame

if let listContainerView = listContainer as? UIView {
listContainerView.layoutSubviews()
}

reloadDataWithoutListContainer()
}else {
if collectionView.frame != targetFrame {
Expand Down Expand Up @@ -356,18 +361,6 @@ open class JXSegmentedView: UIView, JXSegmentedViewRTLCompatible {
collectionView.setContentOffset(CGPoint(x: max(min(maxX, targetX), minX), y: 0), animated: false)

if contentScrollView != nil {
if contentScrollView!.frame.equalTo(CGRect.zero) &&
contentScrollView!.superview != nil {
//某些情况系统会出现JXSegmentedView先布局,contentScrollView后布局。就会导致下面指定defaultSelectedIndex失效,所以发现contentScrollView的frame为zero时,强行触发其父视图链里面已经有frame的一个父视图的layoutSubviews方法。
//比如JXSegmentedListContainerView会将contentScrollView包裹起来使用,该情况需要JXSegmentedListContainerView.superView触发布局更新
var parentView = contentScrollView?.superview
while parentView != nil && parentView?.frame.equalTo(CGRect.zero) == true {
parentView = parentView?.superview
}
parentView?.setNeedsLayout()
parentView?.layoutIfNeeded()
}

contentScrollView!.setContentOffset(CGPoint(x: CGFloat(selectedIndex) * contentScrollView!.bounds.size.width
, y: 0), animated: false)
}
Expand Down