 import UIKit
 
 class ImageScrollerView: UIScrollView, ImageCacheDelegate, MotionManagerDelegate{
-
+    
     var imageView = UIImageView()
+    
+    var isAnimating = false
     
     func setup(image: UIImage){
         imageView.image = image

    func changeImage(image: UIImage){
        
        UserMotion.delegate = nil

        var img = self.imageView
        
        let width = UIScreen.mainScreen().bounds.width

    func gotAttitudeRoll(roll: CGFloat) {
        var num = roll
        if abs(roll) > 0.1{
            
            var animateIndex:CGFloat = 0
            
            if contentOffset.x >= 2 && contentOffset.x <= contentSize.width - UIScreen.mainScreen().bounds.width - 2 {
                if num > 0{
                    num = 2
                }else if num < 0 {
                    num = -2
                }
                animateIndex = contentOffset.x + num
            }else{
                return
            }
            
            if !isAnimating{
                self.isAnimating = true
                
                UIView.animateWithDuration(0.05, animations: { () -> Void in
                    self.contentOffset = CGPointMake(animateIndex, 0)
                    }, completion: { (finish) -> Void in
                        self.isAnimating = false
                })
            }
        }
    }
    
}
