Ios 为视图的直接填充/透明部分设置动画

Ios 为视图的直接填充/透明部分设置动画,ios,swift,cocoa-touch,Ios,Swift,Cocoa Touch,我目前有一个自定义视图,其中有一个透明部分。我目前正在通过以下方式创建: override func drawRect(rect: CGRect) { bgColor.setFill() UIRectFill(rect) let holeRect = imageView.frame let intersect = CGRectIntersection(holeRect, rect) UIColor.clearColor().setFill() UI

我目前有一个自定义视图,其中有一个透明部分。我目前正在通过以下方式创建:

override func drawRect(rect: CGRect) {
    bgColor.setFill()
    UIRectFill(rect)
    let holeRect = imageView.frame
    let intersect = CGRectIntersection(holeRect, rect)
    UIColor.clearColor().setFill()
    UIRectFill(intersect)
}
我还想动画的内部视图是透明的,首先它会变得更小,然后动画的透明部分更大。。。。我将如何着手实现这一点

我现在把它作为我的动画

func startAnimating(completion: () -> Void) {

    let shrinkDuration = animationDuration * 0.5
    let growDuration = animationDuration * 0.9
    self.setNeedsDisplay()
    UIView.animateWithDuration(shrinkDuration, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10, options: .CurveEaseInOut, animations: { () -> Void in
        //Do Animation
        let scaleTransform = CGAffineTransformMakeScale(0.75, 0.75)
        self.imageView.transform = scaleTransform
    }) { (finished) -> Void in
        self.setNeedsDisplay()

        UIView.animateWithDuration(growDuration, animations: { () -> Void in
            let scaleTransform = CGAffineTransformMakeScale(20, 20)
            self.imageView.transform = scaleTransform
            self.alpha = 0
        }, completion: { (finished) -> Void in
            self.removeFromSuperview()
            completion()
        })

    }
}

虽然尝试添加以下动画块,但这不会调整Hol直立部分的大小

UIView.animateWithDuration(0.2, animations: {
    //animate your alpha property here
}, completion: { finished in
    //do whatever you need to do when the animation finish 
})

您正在设置自我的alpha动画,是否要设置自我的alpha动画或imageView动画?在这种情况下,谁是self?self只是UIView的一个子类。视图应该有一个红色背景,在图像视图所在的中心应该是透明的,除了图像之外,您应该能够看到superview。我首先更改imageView/transparent rect的大小,然后淡入并删除整个视图@IcaroNZin在这种情况下,请尝试使用:self.backgroundColor=UIColor..colorWithAlphaComponent(0)代替self。alpha@IcaroNZ我想有,;这是个误会。我可以让淡入淡出的视图正常工作,但我似乎无法设置动画的是“Hol直立”部分的大小抱歉,我现在感到困惑,在您的动画中,您只设置了imageView而不是UIView的动画