2016-06-11 3 views
1

UIPageViewControllerを使い、(ほぼフルスクリーンの)カードの束をユーザーに見せてくれるアプリケーションがあります。しかし、一部のユーザーは、(最初​​に)左/右にスワイプしてすべてのカードを通過することはできません(ドットが画面に表示されていても、それは図になります:)。スワイプが可能であることを示すUIPageViewControllerアニメーション

私の考えは、部分的に次のカードの半分までスワイプした小さな1回限りのアニメーションを実行してから、スワイプが可能であることを直感的にユーザーに示すためにバウンスします。

私はUIPageViewController APIを見ましたが、これを標準的に許可する関数はありません。

これを実装する最良の方法は何でしょうか(ただし、まだ標準UIPageViewControllerを使用しています)? UIPageViewControllerに偽のジェスチャーを送ることは可能でしょうか?

+0

フェイクこと。ページビューコントローラーのように見えるビューを配置し、アニメーションします。 – matt

+0

私はそれを行うことができますが、それはページビューとまったく同じレイアウトを再作成しなければならないということです。たぶん私は基本的なスクロールビューのアクセスを得ることができたと私はちょうど不思議だったと何かを行う... – HixField

+0

再作成、いいえ。スナップショットを撮るだけです。 – matt

答えて

2

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 
    } 


} 
関連する問題