views:

74

answers:

1

Hi there,

I am looking for a way to turn off the iPhone screen without the iPhone going to sleep. I don't really mind if turning the screen off is against apple rules. Would setting window alpha to 0 do the trick? Is there maybe some sort of boolean value I can change?

If anyone has an ideas they would be much appreciated.

Many thanks,

Stu

+3  A: 

First make the statusbar invisible:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

Then create a subview with the backgroundColor to black:

CGRect rect = [[UIScreen mainScreen] applicationFrame];
UIView *bg = [[UIView alloc] initWithFrame:rect];
bg.backgroundColor = [UIColor blackColor];
[window addSubview:bg];

The reason for making the statusbar hidden first, is so that the [[UIScreen mainScreen] applicationFrame] call will cover the whole screen.

Gerald Kaszuba
That is a good idea, thanks!
Stumf
I mostly use this for a "loading" screen, with a UIActivityIndicatorView in the middle of it. The bg.alpha would be set to 0.5 it gives the effect of a faded background.
Gerald Kaszuba