Change UIView alpha value

Posted by Ask on Stack Overflow See other posts from Stack Overflow or by Ask
Published on 2012-07-07T15:18:09Z Indexed on 2012/07/07 21:16 UTC
Read the original article Hit count: 165

Filed under:
|
|
|

I'm trying to create an UIView and change its alpha property to simulate backlight change. Here is my code

        if (TransparentView == nil) {
            TransparentView = [[UIView alloc] initWithFrame:self.view.bounds];
            TransparentView.backgroundColor = [UIColor whiteColor];
            self.view = TransparentView;
        }

    start=start+appDelegate.OnOffTime;
        TransparentView.alpha = 0.2; 
    float step = 1.0 / ( appDelegate.OnOffTime * 100);
    for (float f = 0; f < 1; f=f+step) {
        TransparentView.alpha = (CGFloat)(1 - f);
        [NSThread sleepForTimeInterval:0.01];
}

Both TransparentView.alpha = 0.2 and TransparentView.alpha = (CGFloat)(1 - f) do change TransparentView.alpha, but only TransparentView.alpha = 0.2 changes real device "brightness'. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios