Miriam Roberts
Miriam Roberts

Reputation:

How to make iPhone screen dim

I have a refresh button on my iphone screen that refreshes a table in the current view.

The screen refresh beautifully, but is there a way I can make the screen dim and then lighten again after the table has refreshed?

Upvotes: 6

Views: 6182

Answers (2)

teabot
teabot

Reputation: 15444

You could place a non-opaque view with a black background over the view you wish to dim. This would have an alpha value of 0 by default and thus be transparent. You could then use a UIView animation to set the black views alpha from 0 to 0.5 (say) and then back.

Note: The code below has not been tested but I have used similar to achieve the same effect.

    ...
    dimView.alpha = 0.0f;
    [UIView beginAnimations@"fade" context:nil];
    [UIView setAnimationDuration:0.5f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView setAnimationRepeatAutoreverses:YES];
    dimView.alpha = 0.5f;
    [UIView commitAnimations];
    ...
}

- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    dimView.alpha = 0.0f;
}

Upvotes: 15

Xetius
Xetius

Reputation: 46784

Could you load a black, 50% alpha view over the top, possibly fade in?

Upvotes: 1

Related Questions