0

I am trying to create my first iphone app and I have a view that is supposed to be pitch black. My view is connected to my controller properly (my label shows when I run the simulator).

I want to add a black layer (so the screen looks like the iphone is off). Not only this, when the user pushes or interacts with the screen it should only be triggering those actions onto the black layer. I will have something underneath that layer, like a label persay.

When I set the brightness to 0.0 in my controller and run the simulator it still shows the view:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            [[UIScreen mainScreen] setBrightness: 0.0]; //<-- here
            // Custom initialization
        }
        return self;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [[UIScreen mainScreen] setBrightness: 0.0]; //<-- here as well. but nothing happens
        self.navigationItem.hidesBackButton = YES;
        // Do any additional setup after loading the view.
    }

Also, I feel like setting the brightness would still allow the user to interact with the screen, which isn't what I want. Could anyone help? Could I just add a black image or something?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
bigpotato
  • 26,262
  • 56
  • 178
  • 334
  • Just add a subview with a black background colour with a frame that's equal to the bounds of your view controller and add gesture recognisers which will only be recognised by that view. Note: If you've added any gesture recognisers to the view controller's view then these will be picked up on the black view too. – sooper May 26 '14 at 22:44

2 Answers2

0

You could add a completely black UIView on top of your current view.

UIView *blackView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
blackView.backgroundColor = [UIColor blackColor];
[viewIWantToObscure addSubview:blackView];

This would render the view you want to cover up (viewIWantToObscure) completely blacked out. As for the second part of your requirement, touching though the view, more infromation about sending touches up the view hierarchy can be found here.

Community
  • 1
  • 1
Brian Tracy
  • 6,801
  • 2
  • 33
  • 48
-1

You have to place the setBrightness statement in - (void)applicationDidBecomeActive:(UIApplication *)application -- it has no effect anyplace else. To clean up after your app, you should restore brightness in - (void)applicationWillResignActive:(UIApplication *)application.

GlennRay
  • 959
  • 9
  • 18