yysskk / SwipeMenuViewController

Swipable tab and menu View and ViewController.
MIT License
1.29k stars 131 forks source link

while tabView.style is segmented,the tabView.underlineView.margin is wrong at beginning #25

Closed chaoshenglu closed 6 years ago

chaoshenglu commented 6 years ago

options.tabView.style = .segmented options.tabView.backgroundColor = .white options.tabView.underlineView.backgroundColor = .red options.tabView.underlineView.height = 3 options.tabView.underlineView.margin = 20 options.tabView.itemView.textColor = .black options.tabView.itemView.selectedTextColor = .red options.tabView.height = 45 options.tabView.itemView.font = UIFont.systemFont(ofSize:15) swipeMenuView.reloadData(options: options)

chaoshenglu commented 6 years ago

I found out the reason: TabView.swift

underlineView.frame.origin.x = adjustCellWidth CGFloat(index) - options.underlineView.margin ⬇️ underlineView.frame.origin.x = adjustCellWidth CGFloat(index) + options.underlineView.margin

chaoshenglu commented 6 years ago

fileprivate func resetUnderlineViewPosition(index: Int) { guard options.style == .segmented, dataSource.numberOfItems(in: self) > 0 else { return } let adjustCellWidth: CGFloat if #available(iOS 11.0, ), options.isSafeAreaEnabled && safeAreaInsets != .zero { adjustCellWidth = (frame.width - options.margin 2 - safeAreaInsets.left - safeAreaInsets.right) / CGFloat(dataSource.numberOfItems(in: self)) - options.underlineView.margin 2 } else { adjustCellWidth = (frame.width - options.margin 2) / CGFloat(dataSource.numberOfItems(in: self)) - options.underlineView.margin * 2 }

    DispatchQueue.main.asyncAfter(deadline: .now()+0.1) {
        let x = adjustCellWidth * CGFloat(index) + self.options.underlineView.margin
        let y = self.containerView.height
        let width = adjustCellWidth
        let height = self.options.underlineView.height
        self.underlineView.frame = CGRect(x:x,y:y,width:width,height:height)
    }
}
chaoshenglu commented 6 years ago

DispatchQueue.main.asyncAfter(deadline: .now()+0.1) { let x = adjustCellWidth CGFloat(index) + self.options.underlineView.margin CGFloat(index*2+1) let y = self.containerView.frame.size.height let width = adjustCellWidth let height = self.options.underlineView.height self.underlineView.frame = CGRect(x:x,y:y,width:width,height:height) }

yysskk commented 6 years ago

@chaoshenglu Thanks, report :-) This problem was resloved by https://github.com/yysskk/SwipeMenuViewController/pull/37

angelen10 commented 5 years ago

@yysskk When update to 3.0.0, this bug appear. The code in TabView.swift in line 397:

additionView.frame.origin.x = adjustCellWidth * CGFloat(index) - options.additionView.padding.left

should change to:

additionView.frame.origin.x = adjustCellWidth * CGFloat(index) + options.additionView.padding.left