Making a custom keyboard on iPad, need help with some parts
Right now I'm making a custom keyboard for an app. I've set up a keyboard that mimics the look of the regular keyboard, but with specific keys that I put in. I also set up a view controller that has the image along with a series of transparent UIButtons placed over each of the keys in IB. Here's the code so far:
//CustomKeyBoardViewController.h
#import <UIKit/UIKit.h>
@protocol CustomKeyBoardViewControllerDelegate
- (void) buttonTapped:(NSString*)text;
- (void) doneTapped;
@end
@interface CustomKeyBoardViewController : UIViewController {
id<CustomKeyBoardViewControllerDelegate> _delegate;
}
-(IBAction)spaceTapped:(id)sender;
-(IBAction)goTapped:(id)sender;
-(IBAction)xTapped:(id)sender;
-(IBAction)plusTapped:(id)sender;
-(IBAction)minusTapped:(id)sender;
-(IBAction)arrowTapped:(id)sender;
-(IBAction)slashTapped:(id)sender;
-(IBAction)oneTapped:(id)sender;
-(IBAction)twoTapped:(id)sender;
-(IBAction)threeTapped:(id)sender;
-(IBAction)fourTapped:(id)sender;
-(IBAction)fiveTapped:(id)sender;
-(IBAction)sixTapped:(id)sender;
-(IBAction)sevenTapped:(id)sender;
-(IBAction)eightTapped:(id)sender;
-(IBAction)nineTapped:(id)sender;
-(IBAction)zeroTapped:(id)sender;
@property(nonatomic, assign) id<CustomKeyBoardViewControllerDelegate> _delegate;
@end
//CustomKeyBoardViewController.m
#import "CustomKeyBoardViewController.h"
@implementation CustomKeyBoardViewController
@synthesize _delegate, Keyboard;
- (IBAction)spaceTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@" "];}}
- (IBAction)goTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"Go"];}}
- (IBAction)xTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"x"];}}
- (IBAction)plusTapped:开发者_JS百科(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"+"];}}
- (IBAction)minusTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"-"];}}
- (IBAction)arrowTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"^"];}}
- (IBAction)slashTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"/"];}}
- (IBAction)oneTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"1"];}}
- (IBAction)twoTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"2"];}}
- (IBAction)threeTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"3"];}}
- (IBAction)fourTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"4"];}}
- (IBAction)fiveTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"5"];}}
- (IBAction)sixTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"6"];}}
- (IBAction)sevenTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"7"];}}
- (IBAction)eightTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"8"];}}
- (IBAction)nineTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"9"];}}
- (IBAction)zeroTapped:(id)sender {if (_delegate != nil) {[_delegate buttonTapped:@"0"];}}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return ((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];}
- (void)viewDidUnload {[super viewDidUnload];}
- (void)dealloc {[super dealloc];}
@end
I've gotten this figured out with help from this and this.
The issue is using it in another view controller. I've read that you need to use a custom UIView and make it the inputView for that view controller's text fields.
What I need help with is putting this in a view instead of a view controller in a way that works. These are my main questions:
Do I need to put all of this code in the view instead?
Do I even need this view controller?
If I don't need the view controller, what do I need to do to put the image of the keyboard in the view?
Any help is appreciated
精彩评论