Skip to content

Commit ba263b1

Browse files
committed
fixed a layout when cells is centered and overlay menu style.
1 parent 8b80d4d commit ba263b1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Sources/Menu Cells/Overlay/OverlayMenuCell.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public class OverlayMenuCell: PagingMenuViewCell {
9494

9595
func setFrame(_ menuView: PagingMenuView, maskFrame: CGRect, animated: Bool) {
9696
textMaskView.frame = menuView.convert(maskFrame, to: highlightLabel).inset(by: maskInsets)
97+
98+
if let expectedOriginX = menuView.getExpectedAlignmentPositionXIfNeeded() {
99+
textMaskView.frame.origin.x += expectedOriginX
100+
}
97101
}
98102

99103
public func calculateWidth(from height: CGFloat, title: String) -> CGFloat {

Sources/PagingMenuView.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,23 @@ open class PagingMenuView: UIScrollView {
652652

653653
/// If contentSize.width is not over safe area, paging menu view applys cellAlignment to each the cells.
654654
private func alignContainerViewIfNeeded() {
655-
let expectedOriginX = cellAlignment.calculateOriginX(from: maxSafedOffset)
656-
guard !hasScrollableArea && expectedOriginX != containerView.frame.origin.x else {
655+
guard let expectedOriginX = getExpectedAlignmentPositionXIfNeeded() else {
657656
return
658657
}
659-
660-
containerView.frame.origin.x = expectedOriginX
658+
659+
if expectedOriginX != containerView.frame.origin.x {
660+
containerView.frame.origin.x = expectedOriginX
661+
}
662+
}
663+
664+
665+
/// get correct origin X of menu view's container view, If menu view is scrollable.
666+
func getExpectedAlignmentPositionXIfNeeded() -> CGFloat? {
667+
let expectedOriginX = cellAlignment.calculateOriginX(from: maxSafedOffset)
668+
guard !hasScrollableArea else {
669+
return nil
670+
}
671+
return expectedOriginX
661672
}
662673

663674

0 commit comments

Comments
 (0)