     override func renderPageAtIndex(index: Int, inContext context: CGContext) {
         // 現在のページ数を保存する.
         if (index > 0) {
-            UserDefaults.standard.set(index - 1, forKey: UDKey.CurrentPage)
+            
+            if (preIndex < index) {
+                print("to right")
+                UserDefaults.standard.set(index - 1, forKey: UDKey.CurrentPage)
+            } else {
+                print("to left")
+                UserDefaults.standard.set(index, forKey: UDKey.CurrentPage)
+            }
+            
             UserDefaults.standard.synchronize()
         }
 

    var disposeBag = DisposeBag()
    var bookInfo : LocalBookInfo!
    let model = BookModel()

    @IBAction func doClose() {
        self.dismiss(animated: true, completion: nil)

                    }
                })
            }
        }.addDisposableTo(disposeBag)
        self.tapView.addGestureRecognizer(recognizer)
        self.view.bringSubview(toFront: tapView)
