我正在使用XLPagerTabStrip
获取具有类似Android的TabBar
类型行为的ViewPager
。我已经按照他们的github repo文档指南进行了配置,但就我而言,它在我的模拟器iPhone11 Pro max和真实设备iPhone 6+上都有特殊的行为。尽管不需要滚动,但标签栏在选择最后一个标签时会滚动一点。在iPhone 6中,它会显示单个选项卡的全屏。我正在附上代码和屏幕截图。任何帮助都是可取的。提前致谢
这是我的代码
class TalkRoomPagerViewController: BaseButtonBarPagerTabStripViewController<PagerTabCell>, StoryboardBased, ViewModelBased {
var viewModel: TalkRoomPagerViewModel!
private let bag = DisposeBag()
private var allTalkRoom: TalkRoomListViewController {
let viewModel = TalkRoomListViewModel(type: .all,
filteredTalkroomWithPreferenceLists: self.viewModel.allTalkRoomWithPreferenceLists,
requestPreferenceUpdate: self.viewModel.requestPreferenceUpdate,
pagerTabIndex: self.viewModel.pagerTabIndexSubject.asObserver())
let services = TalkroomListServices(chatRoomNetwork: ChatRoomNetwork())
let viewController = TalkRoomListViewController.instantiate(withViewModel: viewModel, andServices: services)
return viewController
}
private var siteTalkRoom: TalkRoomListViewController {
let viewModel = TalkRoomListViewModel(type: .site,
filteredTalkroomWithPreferenceLists: self.viewModel.siteTalkRoomWithPreferenceLists,
requestPreferenceUpdate: self.viewModel.requestPreferenceUpdate)
let services = TalkroomListServices(chatRoomNetwork: ChatRoomNetwork())
let viewController = TalkRoomListViewController.instantiate(withViewModel: viewModel, andServices: services)
return viewController
}
private var companyTalkRoom: TalkRoomListViewController {
let viewModel = TalkRoomListViewModel(type: .company,
filteredTalkroomWithPreferenceLists: self.viewModel.companyTalkRoomWithPreferenceLists,
requestPreferenceUpdate: self.viewModel.requestPreferenceUpdate)
let services = TalkroomListServices(chatRoomNetwork: ChatRoomNetwork())
let viewController = TalkRoomListViewController.instantiate(withViewModel: viewModel, andServices: services)
return viewController
}
private var groupTalkRoom: TalkRoomListViewController {
let viewModel = TalkRoomListViewModel(type: .group,
filteredTalkroomWithPreferenceLists: self.viewModel.groupTalkRoomWithPreferenceLists,
requestPreferenceUpdate: self.viewModel.requestPreferenceUpdate)
let services = TalkroomListServices(chatRoomNetwork: ChatRoomNetwork())
let viewController = TalkRoomListViewController.instantiate(withViewModel: viewModel, andServices: services)
return viewController
}
public var steppers: [Stepper] {
return [viewModel, allTalkRoom.viewModel, siteTalkRoom.viewModel, companyTalkRoom.viewModel, groupTalkRoom.viewModel]
}
override func viewDidLoad() {
self.prepareUI()
self.configureNavigationBar()
super.viewDidLoad()
bindViewModel()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.requestTalkRoomList.onNext(())
viewModel.requestPreferenceList.onNext(())
viewModel.locationFilter.accept(PersistenceManager.shared.savedFilterLocation)
}
func bindViewModel() {
viewModel.pagerTabIndexSubject.subscribe(onNext: { (index) in
self.moveToViewController(at: index, animated: true)
})
.disposed(by: bag)
viewModel.preferenceUpdateResponse.subscribe(onNext: { [weak self] _ in
self?.viewModel.requestTalkRoomList.onNext(())
self?.viewModel.requestPreferenceList.onNext(())
})
.disposed(by: bag)
}
private func prepareUI() {
self.title = "トークルーム一覧"
buttonBarView.isScrollEnabled = false
buttonBarItemSpec = ButtonBarItemSpec.nibFile(nibName: "PagerTabCell", bundle: Bundle(for: PagerTabCell.self)) { _ in
return self.view.frame.width/4
}
settings.style.buttonBarBackgroundColor = .white
settings.style.buttonBarItemBackgroundColor = .white
settings.style.selectedBarBackgroundColor = Asset.duskBlue.color
settings.style.selectedBarHeight = 2.0
settings.style.buttonBarMinimumLineSpacing = 0
settings.style.buttonBarItemTitleColor = .black
settings.style.buttonBarLeftContentInset = 0
settings.style.buttonBarRightContentInset = 0
changeCurrentIndexProgressive = { (oldCell: PagerTabCell?, newCell: PagerTabCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
guard changeCurrentIndex == true else { return }
oldCell?.titleLabel.textColor = .black
newCell?.titleLabel.textColor = Asset.duskBlue.color
}
}
private func configureNavigationBar() {
self.addBarItem(position: .left, title: "編集", target: self, action: #selector(editButtonTapped))
self.addBarItem(position: .right, image: Asset.iconPlus.image, target: self, action: #selector(addButtonTapped))
}
@objc private func editButtonTapped() {
}
@objc private func addButtonTapped() {
self.viewModel.navigateToCreateTalkRoom()
}
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
return [allTalkRoom, siteTalkRoom, companyTalkRoom, groupTalkRoom ]
}
override func configure(cell: PagerTabCell, for indicatorInfo: IndicatorInfo) {
cell.iconImageView.image = indicatorInfo.image?.withRenderingMode(.alwaysOriginal)
cell.titleLabel.text = indicatorInfo.title
}
}
最佳答案
我不知道您的代码中有什么问题,但是我使用了XLPagerTabStrip并遇到了同样的问题。他们的文档很少。我从Github下载了他们的演示示例代码。我只是从情节提要和代码中复制粘贴他们的视图控制器。之后,我会根据自己的要求对其进行修改。
如果您使用的是Xcode 11或更高版本,请检查您应用的亮模式和暗模式功能。如果您的应用程序完全处于亮模式,则提供暗模式支持。
希望对您有所帮助。
关于ios - iOS框架XLPagerTabStrip无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59172752/