gpt4 book ai didi

iOS 框架 XLPagerTabStrip 无法正常工作

转载 作者:行者123 更新时间:2023-11-29 05:16:07 28 4
gpt4 key购买 nike

我正在使用 XLPagerTabStrip 获取具有 ViewPager 类型行为的 TabBar,就像 Android 一样。我已经按照他们的 github 存储库文档指南进行了配置,但就我而言,它在我的模拟器 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

}

}

iPhone 6 plus screenshot iPhone 11 Pro Max simulator , initial view iPhone 11 , problematic scenario

最佳答案

  1. 我不知道您的代码有什么问题,但我使用过 XLPagerTabStrip &遇到同样的问题。他们的文档很少。我从 Github 下载了他们的演示示例代码。我只是从 Storyboard和代码中复制粘贴他们的 View Controller 。之后我根据自己的要求进行修改。

  2. 如果您使用的是 Xcode 11 或更高版本,请检查您的应用程序的浅色模式和深色模式功能。如果您的应用程序完全处于浅色模式,则提供深色模式支持。我希望这对您有所帮助。

关于iOS 框架 XLPagerTabStrip 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59172752/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com