Imágenes de fondo en la página Vista Superposición del controlador en reversa
tengo unpageViewController
que muestra una imagen de fondo por el índice. Funciona bien deslizando de izquierda a derecha (hacia adelante), pero cuando desliza hacia atrás las imágenes de fondo se superponen entre sí. Antes de implementar la imagen de fondo, la interfaz de usuario en cada VC funcionaba bien hacia adelante y hacia atrás, así que sé que es la imagen de fondo. También si cambio apage curl
en lugar descroll
en mistoryboard
funciona bien a la inversa, simplemente no funciona parascroll
. Esto aparentemente es un error conocido (Eliminar un controlador de vista de UIPageViewController) sin embargo, necesito una solución en Swift.
pageviewController:
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
guard
let currentPageViewController = viewController as? SinglePageViewController,
let currentIndex = indexOfForecast(currentPageViewController.forecast!) as? Int where currentIndex != 0 else { return nil } //fixed bug where index was -0 only on scroll
return viewControllerAtIndex(currentIndex - 1)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
guard
let lastForecast = forecasts?.last,
let currentPageViewController = viewController as? SinglePageViewController, currentForecast = currentPageViewController.forecast,
let currentIndex = indexOfForecast(currentForecast) as? Int where currentIndex != forecasts?.indexOf(lastForecast) else {return nil}
return viewControllerAtIndex(currentIndex + 1)
}
func viewControllerAtIndex(index: Int) -> UIViewController? {
if let forecast = forecasts?[index] {
let time = forecastTimes[index]
let imageURL = conditionsIcons[index]
let backgroundImageName = backgroundImageNames.names[index]
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("SinglePageViewController") as! SinglePageViewController
vc.forecast = forecast
vc.time = time
vc.imageURL = imageURL
vc.backgroundImageName = backgroundImageName
return vc
}
return nil
}
func showVC() {
if let firstVC = viewControllerAtIndex(0) {
busyAlertController.dismiss()
let viewControllers = [firstVC]
self.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}
}
singlePageViewController:
override func viewDidLoad() {
super.viewDidLoad()
backgroundImage = UIImageView(image: UIImage(named: backgroundImageName!))
backgroundImage.contentMode = UIViewContentMode.ScaleAspectFill
self.view.insertSubview(backgroundImage, atIndex: 0)
}