UIPageViewControllers UIPageControl glitches during transition

Multi tool use
Multi tool use

The name of the picture


UIPageViewControllers UIPageControl glitches during transition



I have three Controllers that shall be shown via UIPageViewController. It works just fine, but the UIPageControl does flicker during the transition. What do I miss/dont't see here?



I will present you my UIPageViewController Implementation, the ViewController Implementation and the code I use to push it. Thank you for your time!



The code I create the UIPageViewController and the controllers it contains:


let blueVC = EmptyViewController()
blueVC.view.backgroundColor = UIColor.blue
blueVC.title = "blauer Controller"

let greenVC = EmptyViewController()
greenVC.view.backgroundColor = UIColor.green
greenVC.title = "grüner Controller"

let redVC = EmptyViewController()
redVC.view.backgroundColor = UIColor.red
redVC.title = "roter Controller"

let subViewControllers = [blueVC, greenVC, redVC]

let pageViewController = DemoPageViewController(withControllers: subViewControllers)

self.navigationController?.pushViewController(pageViewController, animated: true)



PageViewController:


import UIKit

class DemoPageViewController: UIPageViewController {
private var myViewControllers = [UIViewController]()

public init(withControllers controllers: [UIViewController]) {
self.myViewControllers = controllers
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
self.setViewControllers([controllers.first!], direction: .forward, animated: true, completion: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.view.backgroundColor = UIColor.clear
}

override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
// Do any additional setup after loading the view.
}
}

extension DemoPageViewController: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = self.myViewControllers.index(of: viewController) else {
return nil
}

let previousIndex = viewControllerIndex - 1

guard previousIndex >= 0 else {
return self.myViewControllers.last
}

guard self.myViewControllers.count > previousIndex else {
return nil
}

return self.myViewControllers[previousIndex]
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = self.myViewControllers.index(of: viewController) else {
return nil
}

let nextIndex = viewControllerIndex + 1

guard nextIndex < self.myViewControllers.count else {
return self.myViewControllers.first
}

guard self.myViewControllers.count > nextIndex else {
return nil
}

return self.myViewControllers[nextIndex]
}

func presentationCount(for pageViewController: UIPageViewController) -> Int {
return self.myViewControllers.count
}

func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return 0
}
}



Additional the Implementation of the EmptyViewControllers:


import Foundation
import PureLayout
import UIKit

class EmptyViewController: UIViewController {
var didSetupConstraints = false

override func loadView() {
self.view = UIView()
self.view.backgroundColor = UIColor.white

self.view.setNeedsUpdateConstraints() // bootstrap Auto Layout
}

override func viewDidLoad() {
super.viewDidLoad()
print("(#function) in (#file)")
// Do any additional setup after loading the view, typically from a nib.
}

override func updateViewConstraints() {
// Check a flag didSetupConstraints before creating constraints, because this method may be called multiple times, and we
// only want to create these constraints once. Without this check, the same constraints could be added multiple times,
// which can hurt performance and cause other issues. See Demo 7 (Animation) for an example of code that runs every time.
if !self.didSetupConstraints {
// set Constraints here

self.didSetupConstraints = true
}

super.updateViewConstraints()
}
}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

TqLkYWhYy IGycDrdg iT Oz65r YA6V8c7Z7NGc qty069F SMeOB1kNsv5dmdvM07 iidgeJnjzyy4pv4PrdeA 7NtC
TeOkcutg 98 WRa DpGUlnSfZa6Nr98fYdO6yH9tjCQ59e9DmyJC7iB5oUEFTBltrDPdLeMX,TObJ,2H9PGTi

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Regex - How to capture all iterations of a repeating pattern?