views:

509

answers:

2

Hello. Let's start with an example: when you enter the Contact program on your iPhone, then type on the TextField "Search", the keyboard is displaying itself and the tableView under is going dark (and deactivated). Then if I touch this dark deactivated list, the keyboard hides itself and the list becomes normal.

I would like to reproduce this functionality, but I don't know how. Is there a Cocoa method, or do I have to re-develop that by myself ?

Thanks for your advices.

Mart

+1  A: 

I'm pretty sure you are going to need to develop that for yourself. Looking at the effect on my phone, I think I would have a completely transparent (but black) UIView overlaying my UITableView. Register for the UIKeyboardWillShow notification, and when you receive it, animate the opacity of that UIView to 70%. Reverse the process on UIKeyboardWillHide.

mmc
If you're using a UIButton, tapping it for releasing the keyboard is also easy. Set the button type to custom and the backgroundColor to black with 0.7 alpha.
Nikolai Ruhe
Thanks for your hints, guys.However, i think it's pretty strange that Apple didn't put this functionality in its cocoa SDK.
Martin
The idea of making the view a button is a very good one.
mmc
+2  A: 

I would even set the UIView to a uibutton so you can dismiss the keyboard when you want. Oh, That was there already!

OK, here's a bit of code that demonstrates how to add the button itself:

   CGRect frame = CGRectMake(0,
                                                      0,
                                                      [self parentViewController].view.bounds.size.width,
                                                      [self parentViewController].view.bounds.size.height);
    imageView = [[UIButton alloc] initWithFrame:frame];
    [imageView setAlpha:0];
    imageView.opaque = NO;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2];
    [imageView setAlpha:0.8];
    imageView.backgroundColor = [UIColor blackColor];
    [UIView commitAnimations];
    [imageView addTarget:self action:@selector(lockedScreenAction:) forControlEvents:UIControlEventTouchUpInside];

    [[self parentViewController].view addSubview:imageView];
Cyril Godefroy
Thanks Cyril.Now I can just make a copyNpaste to my code and it would work perfectly :)
Martin