UIPageViewControllerの標準的な動作を使用する方法が見つかりました。 基本的にはシンプルですが、ビューがロードされるまで待ってから、0.5秒後に次のページ(プログラム的に)に移動します。最初のアニメーションが終了する直前(0.25秒)前のページ。
あなたはそのも含まれ、私は私のコードでは、施設の遅延に遅延機能を使用していますことに注意してください、私のコードを見ることができます下:
///executes the supplied closure after x seconds on the main queue
public func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
class VCPager: VCPagBase, ProtocolVCScanResult, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
var product : Product?
var productMatch : ProductMatch?
var disableAlternatives : Bool = false
//the loadView is a proprietary function that just loads the view from the storyboard, nothing special
lazy var vcPage1 = VCPage1.loadView()
lazy var vcPage2 = VCPage2.loadView()
var currentPageIndex : Int = 0
override func viewDidLoad() {
super.viewDidLoad()
dataSource=self
delegate=self
setViewControllers([pageForindex(0)!], direction: .Forward, animated: false, completion: nil)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
hintSwipe()
}
//MARK: - helper functions
func hintSwipe() {
delay(0.5) {
self.carrouselJumpForward()
}
delay(0.75) {
self.carrouselJumpBack()
}
}
func pageForindex(pageIndex : Int) -> UIViewController? {
let vc : VCScanResultPageRoot?
switch(pageIndex) {
case -1 : vc = vcPage2
case 0 : vc = vcPage1
case 1 : vc = vcPage2
case 2 : vc = vcPage1
default : vc = nil
}
vc?.passAlongModelFrom(self)
return vc
}
func indexForPage(vc : UIViewController) -> Int {
if vc == vcPage1 { return 0 }
if vc == vcPage2 { return 1 }
//not found = 0
return 0
}
func carrouselJumpForward() {
currentPageIndex += 1
setViewControllers([self.pageForindex(currentPageIndex)!], direction: .Forward, animated: true, completion: nil)
}
func carrouselJumpBack() {
currentPageIndex += -1
setViewControllers([self.pageForindex(currentPageIndex)!], direction: .Reverse, animated: true, completion: nil)
}
//MARK: - UIPageView
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let currentPageIndex = indexForPage(viewController)
return pageForindex(currentPageIndex+1)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let currentPageIndex = indexForPage(viewController)
return pageForindex(currentPageIndex-1)
}
func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
guard let vcCurrentPage = previousViewControllers.first where finished else {
return
}
currentPageIndex = indexForPage(vcCurrentPage)
}
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return 2
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return currentPageIndex
}
}
フェイクこと。ページビューコントローラーのように見えるビューを配置し、アニメーションします。 – matt
私はそれを行うことができますが、それはページビューとまったく同じレイアウトを再作成しなければならないということです。たぶん私は基本的なスクロールビューのアクセスを得ることができたと私はちょうど不思議だったと何かを行う... – HixField
再作成、いいえ。スナップショットを撮るだけです。 – matt