2016-05-23 3 views
3

私はiPad/iPhoneの両方のアプリケーションを持っていて、iPhone 4S、5、5Sを除くすべてのバージョンで動作します。UIPageViewController - ページをプログラム的に変更すると、iPhone 4s/5/5sで動作しなくなる

私はセルとしてWebViewsを持つUIPageViewControllerを持っています。 私は別の単純なUICollectionViewをページセレクタとして使用しています。その機能は、選択されたXページ目にジャンプする機能です。

私のコードはとてもシンプルです:私は "slideToPage(index)"関数を適用するためにUIPageViewControllerに触れたセルのインデックスを渡します。

enter image description here:iPhone 4S/5/5S、アニメーションが完了すると、それは瞬時に古いページに戻りますので、ユーザーがページをジャンプすることはできませんし、彼は一度にページ1を回すことができるために

ここに私のコードです:

func slideToPage(index: Int, completion: (() -> Void)?) { 
    let currentViewController = pageViewController?.viewControllers![0] as! WebViewViewController 
    let count = dataSource.controllers.count 
    let currentPageIndex = dataSource.controllers.indexOf(currentViewController)! 

    guard index < count else { return } 

    // Moving forward 
    if index > currentPageIndex { 
     if let vc: WebViewViewController = dataSource.controllers[index] { 
      self.pageViewController!.setViewControllers([vc], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: { 
       void in 
       vc.loadContent() 
      }) 
     } 
    } 
    // Moving backward 
    else if index < currentPageIndex { 
     if let vc: WebViewViewController = dataSource.controllers[index] { 
      self.pageViewController!.setViewControllers([vc], direction: UIPageViewControllerNavigationDirection.Reverse, animated: true, completion: { 
       void in 
       vc.loadContent() 
      }) 
     } 
    } 
} 

EDIT:

問題が目にありますeアニメーション。 setViewControllers()関数内で設定されたアニメーションがfalseの場合、ページビューは正しいビューに移動します。 trueの場合、アニメーションの最後に、ページビューが前のページに戻ります。

+0

これらのデバイスではどのOSが動作していますか?すべて同じですか? –

+0

ええ、すべて同じ(9.3)。シミュレータ(物理デバイスだけでなく)でも、 –

答えて

1

いくつか試した後、私は設定を解決しましたself.pageViewController!.setViewControllers()のアニメーションパラメータです。 iOSのバグと思われます。

したがって、私はisAnimatedを追加しました:bool var iPadデバイスのアニメーションのみを使用します。ここに私のアップデートがあります:

func slideToPage(index: Int, completion: (() -> Void)?) { 
    if index >= dataSource.controllers.count || index < 0 { 
     return 
    } 

    let currentViewController = pageViewController?.viewControllers![0] as! WebViewViewController 
    let currentPageIndex = dataSource.controllers.indexOf(currentViewController)! 
    let isAnimated = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad) 

    // Moving forward 
    if index > currentPageIndex { 
     if let vc: WebViewViewController = dataSource.controllers[index] { 
      self.pageViewController!.setViewControllers([vc], direction: UIPageViewControllerNavigationDirection.Forward, animated: isAnimated, completion: { complete in 
       vc.loadContent() 
      }) 
     } 
    } 
    // Moving backward 
    else if index < currentPageIndex { 
     if let vc: WebViewViewController = dataSource.controllers[index] { 
      self.pageViewController!.setViewControllers([vc], direction: UIPageViewControllerNavigationDirection.Reverse, animated: isAnimated, completion: { complete in 
       vc.loadContent() 
      }) 
     } 
    } 
} 
関連する問題