Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 11-08-2008, 12:24 PM   #2 (permalink)
RickMaddy
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,122
Default

I added a label to the top of the keyboard in my app. I can explain how to add a subview to the keyboard.

First you need to register to receive keyboard notifications. I have the following in my app delegate:

Code:
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
Here is a snippet from my 'keyboardWillShow'. This allows you to get info about the size and location of the keyboard.

Code:
- (void)keyboardWillShow:(NSNotification *)note {
    NSDictionary *info = [note userInfo];
    NSValue *beginPoint = [info objectForKey:UIKeyboardCenterBeginUserInfoKey];
    NSValue *endPoint = [info objectForKey:UIKeyboardCenterEndUserInfoKey];
    NSValue *keyBounds = [info objectForKey:UIKeyboardBoundsUserInfoKey];
    
    CGPoint pntBegin;
    CGPoint pntEnd;
    CGRect bndKey;
    [beginPoint getValue:&pntBegin];
    [endPoint getValue:&pntEnd];
    [keyBounds getValue:&bndKey];
}
The next trick is actually finding the keyboard view. The keyboard view is actually in a second UIWindow separate from your app's main window. So you need to write code to walk all of the windows in the app. Then for each window you need to find the one that has a subview containing the keyboard. I do this by finding the subview whose description contains the string 'UIKeyboard'. I do this to avoid compiler warnings because the real class for the keyboard view isn't exposed via the SDK. But all you need is a UIView reference anyway.

Once you get the keyboard view, along with the coordinates you got earlier, you can now add a subview to the keyboard view.

I'm not going to give all the code because I worked very hard to figure this out on my own and it gives my app a little edge. Hopefully the info I gave will get you far enough to figure the details out.

Enjoy.
RickMaddy is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,717
Threads: 89,177
Posts: 380,482
Top Poster: BrianSlick (7,119)
Welcome to our newest member, harmonlindas
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.