Using "moveToViewController" causes slider to be animated and moved from first tab to tab 3
how to make it set by default to tab 3 without moving ?
override func viewDidAppear(_ animated: Bool) {
self.moveToViewController(at: 3)
}
im having this same issue, can't seem to get a solution
it's supposed to set preCurrentIndex = index if isViewLoaded is false, which it does, but that doesn't seem to actually set the default index
Any news ? i have same problem
Any updates on this problem?
Just found a solution after some tackles. viewWillLayoutSubviews() does the job!
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
moveToViewController(at: customIndexToMove)
}
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
self.moveToViewController(at: 3, animated: false)
}
}
Premise, you need the latest version of the library,This is very useful to me.
If you need animation
override func viewDidLoad() {
super.viewDidLoad()
moveToViewController(at: 3)
}
If no animation is needed
override func viewDidLoad() {
super.viewDidLoad()
buttonBarView.moveTo(index: 3, animated: false, swipeDirection: .none, pagerScroll: .no)
}
Исходя из этого, вам нужна последняя версия библиотеки, это очень полезно для меня.
Если вам нужна анимацияoverride func viewDidLoad() { super.viewDidLoad() moveToViewController(at: 3) }Если анимация не нужна
override func viewDidLoad() { super.viewDidLoad() buttonBarView.moveTo(index: 3, animated: false, swipeDirection: .none, pagerScroll: .no) }
@ReverseScale , i have tried both variants in version 8.1.1, but it isn't works for me. I always make transition to first viewcontroller in collection.
@Ultraa
How about using DispatchQueue.main.async like @dexter199402 did?
override func viewDidLoad() { super.viewDidLoad() DispatchQueue.main.async { self.moveToViewController(at: 3, animated: false) } }
I tried and succeed.
BTW, I tried
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
self.buttonBarView.moveTo(index: 3, animated: false, swipeDirection: .none, pagerScroll: .no)
}
}
then only tab moves to specified, but view controller didn't switch.
@Ultraa
How about usingDispatchQueue.main.asynclike @dexter199402 did?override func viewDidLoad() { super.viewDidLoad() DispatchQueue.main.async { self.moveToViewController(at: 3, animated: false) } }I tried and succeed.
BTW, I tried
override func viewDidLoad() { super.viewDidLoad() DispatchQueue.main.async { self.buttonBarView.moveTo(index: 3, animated: false, swipeDirection: .none, pagerScroll: .no) } }then only tab moves to specified, but view controller didn't switch.
Thank you for answer, i used code like @dexter199402 . It's succeed, but causes a sharp visible jump when opening XLPagerTabController.
override func viewDidLoad() { super.viewDidLoad() DispatchQueue.main.async { self.moveToViewController(at: 3, animated: false) } }
This is not a perfect solution, it can change currentIndex when controller is shown, but it cause controller's didLoad method. And in my test, when call moveToViewController the first button bar title is always selected.
@zhpengkun my current workaround also fixes the initial menu being incorrectly set
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
DispatchQueue.main.async {
self.moveToViewController(at: 3, animated: false)
// needed or first tab stays highlighted
self.reloadPagerTabStripView()
}
}
https://github.com/xmartlabs/XLPagerTabStrip/issues/537#issuecomment-387295788 almost works fine. But viewDidLayoutSubviews is called while navigating to other ViewControllers too. So I wrote:
private var initialized = false
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if initialized == false {
moveToViewController(at: 3, animated: false)
initialized = true
}
}
Most helpful comment