Amit Raj
Amit Raj

Reputation: 1378

Transparency(alpha) is removed from second run in swift

I am loading a sub view through the following code:

HideView.backgroundColor = UIColor.clearColor()
var loadingView = UIView (frame: CGRectMake(120, 190, 90, 90));
loadingView.center = HideView.center
loadingView.backgroundColor = UIColor(red:0.76, green:0.76, blue:0.76, alpha:0.9)
loadingView.clipsToBounds = true;
loadingView.layer.cornerRadius = 10.0
loadingView.layer.shouldRasterize = true
HideView.addSubview(loadingView)

The above code works fine and we can see the background as follows:

enter image description here

But when this screen subview appears again(from second time) transparency is gone as follows:

enter image description here

Upvotes: 0

Views: 37

Answers (1)

Shai
Shai

Reputation: 25619

You're adding a 'loadingView' twice to the 'HiddenView'. That's why it looks blocked on the 2nd run.

Instead, make sure you only add it once.

HideView.backgroundColor = UIColor.clearColor()
if (!addedLoadingView) { // Or anything alike...
    addedLoadingView = YES
    var loadingView = UIView (frame: CGRectMake(120, 190, 90, 90));
    loadingView.center = HideView.center
    loadingView.backgroundColor = UIColor(red:0.76, green:0.76, blue:0.76, alpha:0.9)
    loadingView.clipsToBounds = true;
    loadingView.layer.cornerRadius = 10.0
    loadingView.layer.shouldRasterize = true
    HideView.addSubview(loadingView)
}

Upvotes: 1

Related Questions