Gar*_*abo 4 ios uipageviewcontroller swift
我有一个pageViewController显示每个索引的背景图像.它可以从左向右(向前)轻扫,但是当您反向滑动时,背景图像会相互重叠.在我实现背景图像之前,每个VC上的UI工作正常和反向,所以我知道它是背景图像.此外,如果我改为page curl而不是scroll在我的storyboard反向工作正常,只是不起作用scroll.这显然是一个已知的错误(从UIPageViewController中删除视图控制器)但是我需要一个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)
}
}
Run Code Online (Sandbox Code Playgroud)
singlePageViewController:
override func viewDidLoad() {
super.viewDidLoad()
backgroundImage = UIImageView(image: UIImage(named: backgroundImageName!))
backgroundImage.contentMode = UIViewContentMode.ScaleAspectFill
self.view.insertSubview(backgroundImage, atIndex: 0)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2232 次 |
| 最近记录: |