私はiPad/iPhoneの両方のアプリケーションを持っていて、iPhone 4S、5、5Sを除くすべてのバージョンで動作します。UIPageViewController - ページをプログラム的に変更すると、iPhone 4s/5/5sで動作しなくなる
私はセルとしてWebViewsを持つUIPageViewControllerを持っています。 私は別の単純なUICollectionViewをページセレクタとして使用しています。その機能は、選択されたXページ目にジャンプする機能です。
私のコードはとてもシンプルです:私は "slideToPage(index)"関数を適用するためにUIPageViewControllerに触れたセルのインデックスを渡します。
: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の場合、アニメーションの最後に、ページビューが前のページに戻ります。
これらのデバイスではどのOSが動作していますか?すべて同じですか? –
ええ、すべて同じ(9.3)。シミュレータ(物理デバイスだけでなく)でも、 –