0

As a new AppDeveloper, I've never used orientation. So, I would like to try to learn with a simple task. What I want to do is have the screen fade to black when the device is set face down. Is that something that would be simple to do, that perhaps somebody could assist me in, or provide helpful information?

Thanks! :D Your help is appriciated

Jtaylorapps
  • 5,680
  • 8
  • 40
  • 56
  • What is wrong with the question? It looks to me to be perfectly valid. Please upvote if you can, because I am not unable to ask questions due to this negative vote. Thanks – Jtaylorapps Jan 20 '12 at 00:13

1 Answers1

2

You can use orientation (using the XYZ values when the screen is face down). I do not recommend this, because your screen will fade out even if a user is using the app while lying down, and staring up at the screen.

There is an easier and cleaner way. Notice how during phone calls, having the phone close to your ear blacks out the screen?

You can access that property by monitoring the proximityState property of UIDevice. Details here

Doing something like:

BOOL closeToUser = [[UIDevice currentDevice] proximityState];

will assign a YES to closeUser when the device is face down on a surface of some kind, and a NO when it is not

If the value is YES, you can invoke code to do whatever you want.

Sid
  • 9,508
  • 5
  • 39
  • 60
  • I see. What I'm hoping to do is face down on a surface fades it. Thanks for your view of logic. I'll try it out tomorrow and see if I can't get something to work! – Jtaylorapps Jan 14 '12 at 06:52
  • Ok, I have the boolean down. Now, is there a simple way of creating a fade to black animation? More specifically, the method if it already in the SDK somewhere. I can work the boolean into an if-else statement, but I can't seen to find an animation for it after aobut an hour of searching. Thanks! – Jtaylorapps Jan 14 '12 at 06:55
  • Well I'm assuming you want to programmatically lock the device? That's not in the API (http://stackoverflow.com/questions/832940/programmatically-lock-and-unlock-iphone-screen). If you want to just show a black screen however, create a UIView with a black background and add it as a subview to your window. – Sid Jan 14 '12 at 08:29
  • 1
    Thanks for your help, I appriciate it. I just spent some time adding views and practicing and I can proudly say I finally am able to work with it. thanks again! – Jtaylorapps Jan 15 '12 at 04:10