[Swfit]UIView Extension #5

UIView Extension #5

func fade(fadein:Bool, duration:CGFloat=0.3, operateHidden:Bool=true){
    if operateHidden {
        self.hidden = false
    }
    UIView.setAnimationBeginsFromCurrentState(true)
    UIView.animateWithDuration(NSTimeInterval(duration), delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.CurveLinear,
        animations: { () -> Void in
            self.alpha = (fadein) ? 1.0 : 0.0
        },
        completion: { (finish:Bool) -> Void in
            if operateHidden {
                self.hidden = !fadein
            }
        }
    )
}