             }
         case .Ended:
             xform = self.viewMain.transform
-            if xform.a < 0.5 {
-                setTransformAnimated(CGAffineTransformIdentity)
-            }
-            boundCheck()
+            let frame = boundCheck()
+            self.borderView.frame = CGRectApplyAffineTransform(frame, CGAffineTransformInvert(self.imageTransform))
+            self.borderView.alpha = 1.0
+            UIView.animateWithDuration(0.5, animations: {
+                self.borderView.alpha = 0.0
+            })
         default:
             self.viewMain.transform = xform
         }
     }
     
-    func boundCheck() {
+    func boundCheck() -> CGRect {
         let size = trimmedImage.size
         let data = NSMutableData(length: 4 * Int(size.width) * Int(size.height))!
         //let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)

    var image:UIImage!
    var delegate:SNTrimControllerDelegate!

    private var trimmedImage:UIImage! {
        didSet {
            imageView.image = trimmedImage

            }
        }
        print("bound", frame)
        return frame
    }
}

