我在public static function arrayChangeKeyCaseRecursive(array $array, int $case = null): array
{
$mutated = [];
$mutator = $case === self::KEY_CASE_LOWER ? 'strtolower' : 'strtoupper';
foreach ($array as $key => $value) {
// Mutate string keys
if (is_string($key)) $key = $mutator($key);
// Mutate array values
if (is_array($value)) $value = self::arrayChangeKeyCaseRecursive($value, $case);
$mutated[$key] = $value;
}
return $mutated;
}
中使用了UIPageContol
,如下所示: -
uipageviewcontroller类: -
UIPageViewController
HomeViewController: -
class PageControllerViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
private var pageViewModel :PageViewModel!
init(transitionStyle style: UIPageViewControllerTransitionStyle, navigationOrientation: UIPageViewControllerNavigationOrientation, options: [String : Any]? = nil, withViewModel viewModel:PageViewModel) {
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: options)
pageViewModel = viewModel
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let pageControl = UIPageControl()
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
self.delegate = self
createPageViewController()
setupPageControl()
}
fileprivate func createPageViewController() {
if (pageViewModel.datasourceModel.dataListArray?.count)! > 0 {
let firstController = getItemController(0)!
let startingViewControllers = [firstController]
self.setViewControllers(startingViewControllers, direction: UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil)
}
}
fileprivate func setupPageControl() {
let appearance = UIPageControl.appearance()
appearance.pageIndicatorTintColor = UIColor.red
appearance.currentPageIndicatorTintColor = UIColor.black
appearance.backgroundColor = UIColor(red: 0.93, green: 0.86, blue: 1, alpha:1.0)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
let itemController = viewController as! HomeViewController
if itemController.itemIndex > 0 {
return getItemController(itemController.itemIndex-1)
}
return nil
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
let itemController = viewController as! HomeViewController
if itemController.itemIndex+1 < (pageViewModel.datasourceModel.dataListArray?.count)! {
return getItemController(itemController.itemIndex+1)
}
return nil
}
fileprivate func getItemController(_ itemIndex: Int) -> HomeViewController? {
if itemIndex < (pageViewModel.datasourceModel.dataListArray?.count)! {
let homeViewModel :HomeViewModel = QM_HomeViewModel(withmodel:pageViewModel.datafordisplay(objectatindex: itemIndex))
let ViewController = HomeViewController(nibName: "HomeViewController", bundle: nil, withViewModel: homeViewModel)
ViewController.itemIndex = itemIndex
return ViewController
}
return nil
}
// MARK: - Page Indicator
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return pageViewModel.datasourceModel.dataListArray! .count
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return 0
}
// MARK: - Additions
func currentControllerIndex() -> Int {
let pageItemController = self.currentController()
if let controller = pageItemController as? HomeViewController{
return controller.itemIndex
}
return -1
}
func currentController() -> UIViewController? {
if (self.viewControllers?.count)! > 0 {
return self.viewControllers![0]
}
return nil
}
}
This is the output that i got .Here it works the pageviewcontroller.
所以我需要在此标签栏上方的页面控件。如何做
答案 0 :(得分:0)
更改位置
let pageControlWidht = 200 // depending number of dots
let pageControl : UIPageControl = UIPageControl.init(frame:CGRect.init(x: self.view.frame.size.with/2-pageControlWidht, y: self.view.frame.size.hieght-100, width: pageControlWidht, height: 100))
将UIPageControl
置于上方。您可以使用
self.view.bringSubview(toFront: self.pageControl)
您可以使用以下代码跟踪当前页面,其中PageContentVC
是自定义ViewController
在PageViewController
内滚动您需要在每个ViewController
中存储索引
func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if !completed {
let pageContentView = previousViewControllers[0] as! PageContentVC;
self.pageControl.currentPage = pageContentView.pageIndex;
}
}