私のUICollectionViewCell(高さ= frame.height/3)の1つにUIPageViewControllerがあります。画像番号が で、うまくいきますが、スクロールする必要があります次の画像は3秒ごとに自動的に何をすべきですか?UIpageViewControllerとタイマー
import UIKit
class PageViewController: UIPageViewController , UIPageViewControllerDataSource{
var scrollingTimer = Timer()
let imageNames = ["Apple_Watch_Main" , "Pic2" , "Pic3"]
override func viewDidLoad() {
super.viewDidLoad()
dataSource = self
let frameViewController = FrameViewController()
frameViewController.imageName = imageNames.first
let viewControllers = [frameViewController]
setViewControllers(viewControllers, direction: .forward, animated: true, completion: nil)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
let currentImageName = (viewController as! FrameViewController).imageName
let currentIndex = imageNames.index(of: currentImageName!)
if currentIndex! > 0 {
let frameViewController = FrameViewController()
frameViewController.imageName = imageNames[currentIndex! - 1]
return frameViewController
}
return nil
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
let currentImageName = (viewController as! FrameViewController).imageName
let currentIndex = imageNames.index(of: currentImageName!)
if currentIndex! < imageNames.count - 1 {
let frameViewController = FrameViewController()
frameViewController.imageName = imageNames[currentIndex! + 1]
return frameViewController
}
return nil
}
}
と私は多くのことを検索し、私はこのようなものの任意の完全かつ正確な答え
せずにいくつかの質問を見つけたここで私のセルに0
場合
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch indexPath.item {
case 0 :
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as!ImageCell
let pagecontroller = PageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
self.addChildViewController(pagecontroller)
cell.addSubview(pagecontroller.view)
pagecontroller.view.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height/3)
return cell
case 1 :
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "filterandorganize", for: indexPath) as! FilterAndOrganize
return cell
case 2 :
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Offers", for: indexPath) as! Offers
return cell
case 3 :
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "OfferedProducts", for: indexPath) as! OfferedProducts
cell.firstViewController = self
return cell
default:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Offers", for: indexPath) as! Offers
return cell
}
}
を追加しましたここで私が見つけた答えはありますが、それでも1つのバグがあります。それは、ユーザーがそれを自らスワイプするときです。自動スクロールは完璧ではなく、あるピクチャから別のピクチャにジャンプします。
ありがとうございました...私はまだ分かりませんが...私は私のviewcontroller allreadyを設定しましたが、どこでどのようにターゲット関数 "scrollRoNextItem" –