 public class JWAnimatedImageView:UIImageView
 {
     
-    
-    
     //bound to function 'updateFrame'
     private lazy var displayLink: CADisplayLink = CADisplayLink(target: self, selector: Selector("updateFrame"))
+    //has connecttion with CADisplayLink.frameInterval
+    private var displayRefreshFactors = 1       //default
     
-    // obtained from NSData
+    //obtained from NSData
     private var imageSource: CGImageSourceRef?
-    
-    //as a frame cache queue,obtained by 'frameProducter',max size is 'frameCacheMaxNumber'
-    private var frameCache = [UIImage]()
-    
-    //frameCacheMaxNumber's default is 5
-    private var frameCacheMaxNumber = 5
-    public func setFrameCacheMaxNumber(newFrameCacheMaxNumber:Int)
-        {self.frameCacheMaxNumber = newFrameCacheMaxNumber}
     
     //indexs of frames choosed from imageSource and total number
     private var displayOrder = [Int]()
-    private var imageCount = 0  //initial
-    
+    private var imageCount = 0                  //initial
     
     //the level of integrity of a gif image,The range is 0%(0)~100%(1).we know that CADisplayLink.frameInterval affact the display frames per second,if it is larger, we will only dispaly fewer frames per second,in the other way,we will never display some of frames all the time.So,the level of integrity gives us a limit that the device should show how many frames at list.If it is 100%(1),that means the device displays frames as much as it can.The default number is 0.8,but you can decrease it for a less cpu usage.
-    private var levelOfIntegrity:Float = 0.8    //default
-    private var displayRefreshFactors = 1   //default
-    public func setLevelOfIntegrity(newLevelOfIntegrity:Float)
-        {self.levelOfIntegrity = newLevelOfIntegrity}
-    
-    
+    public var levelOfIntegrity:Float = 0.8    //default
     
     //add gif as NSData
     public func addGifImage(data:NSData){
         self.imageSource = CGImageSourceCreateWithData(data, nil)
         
         //set cover
-        image = UIImage(CGImage: CGImageSourceCreateImageAtIndex(self.imageSource!,0,nil)!)//cover
-        //self.layer.setNeedsDisplay()
-
+        self.currentImage = UIImage(CGImage: CGImageSourceCreateImageAtIndex(self.imageSource!,0,nil)!)
+        
         CalculateFrameDelay(GetDelayTimes())
-        setCurrentImage()
         
         self.displayLink.frameInterval = self.displayRefreshFactors
         self.displayLink.addToRunLoop(.mainRunLoop(), forMode: NSRunLoopCommonModes)
     }
     
+    //image that will be displayed next
     public var currentImage:UIImage?
     
     //the current index of frames when display the gif
     private var displayOrderIndex = 0
+    
+    //dispatch queue
+    private let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0)
     
     //this is an empty function,but program won't work if I delete it,and I don't know why
     override public func displayLayer(layer: CALayer){}

        }
        
        let frameProperties = imageProperties.map(){
                unsafeBitCast(
                    CFDictionaryGetValue($0,
                        unsafeAddressOf(kCGImagePropertyGIFDictionary)),                CFDictionary.self)
        }
        
        let frameDelays:[Float] = frameProperties.map(){
            var delayObject: AnyObject = unsafeBitCast(
                    CFDictionaryGetValue($0,
                        unsafeAddressOf(kCGImagePropertyGIFUnclampedDelayTime)),
                    AnyObject.self)
            let EPS = 10e-10
            if(delayObject.doubleValue<EPS){
                delayObject = unsafeBitCast(CFDictionaryGetValue($0,
                        unsafeAddressOf(kCGImagePropertyGIFDelayTime)), AnyObject.self)
            }
            return delayObject as! Float
        }
        return frameDelays
    }
    
    typealias FrameDelays = [Float]
    private func CalculateFrameDelay(var delays:FrameDelays)
    {
        
        //Factors send to CADisplayLink.frameInterval

            var framelosecount = 0
            for j in 1..<displayPosition.count{
                if(displayPosition[j] == displayPosition[j-1])
                {++framelosecount}
            }
            
            if(Float(framelosecount) <= Float(displayPosition.count) * (1.0 - self.levelOfIntegrity)||i==displayRefreshDelayTime.count-1){
                
                self.imageCount = displayPosition.last!
                self.displayRefreshFactors = displayRefreshFactors[i]
                
                var indexOfold = 0
                var indexOfnew = 0
                
