在iPad上制作自定义键盘需要一些部分的帮助

时间:2011-06-09 23:49:01

标签: xcode ipad

现在我正在为应用程序制作自定义键盘。我已经设置了一个键盘,模仿常规键盘的外观,但是我使用了特定的键。我还设置了一个视图控制器,它具有图像以及放置在每个键上的一系列透明UIButton。 IB。这是迄今为止的代码:

//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:(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

我在thisthis的帮助下弄明白这一点。

问题是在另一个视图控制器中使用它。我已经读过你需要使用自定义UIView并使其成为该视图控制器文本字段的inputView。

我需要帮助的是以一种有效的方式将其放在视图而不是视图控制器中。 这些是我的主要问题:

我是否需要将所有这些代码放在视图中?

我甚至需要这个视图控制器吗?

如果我不需要视图控制器,我需要做什么才能将键盘图像放在视图中?

感谢任何帮助

0 个答案:

没有答案