代码示例创建自己的键盘 [英] code sample to create own keyboard

查看:113
本文介绍了代码示例创建自己的键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找创建自定义键盘的示例,但似乎没有任何帮助。所以请提供一个代码示例来创建我的自定义键盘

I have searched around for making a sample on creating my custom keyboard but nothing seemed to help. So Please provide me a code sample to create my custom keyboard

请帮帮我

推荐答案

YourKeyboard.h:

YourKeyboard.h :

#import <UIKit/UIKit.h>

@protocol YourKeyboardControllerDelegate
-(void) buttonTapped: (int) ASCIICode;
@end

@interface YourKeyboardViewController : UIViewController
{
    id<YourKeyboardControllerDelegate> delegate;
}

@property (nonatomic,weak) id<YourKeyboardControllerDelegate> delegate;


@end

YourKeyboard.m:

YourKeyboard.m :

#import "YourKeyboardViewController.h"

@implementation YourKeyboardViewController
@synthesize  delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}

- (IBAction)buttonTapped:(id)sender {
    if (delegate != nil)
    {
        [delegate buttonTapped:[sender tag]];
    }
}

现在 - 使用任意视图制作您自己的.xib文件你要。使用buttonTapped方法连接每个按钮。将正确的ASCII码分配为每个按钮的标签。我正在使用这个解决方案,一切正常。

Now - make your own .xib file with any view you want. Connect every button with "buttonTapped" method. Assign proper ASCII code as a tag for each button. I am using this solution and everything works fine.

用法:
您正在创建视图控制器作为YourKeyboardControllerDelegate。

Usage: You are creating view controller as a YourKeyboardControllerDelegate.

@interface MainViewController : UIViewController <YourKeyboardControllerDelegate> 
{
   YourKeyboardViewController *keyboard
}

和.m file

- (void)viewDidLoad
{
  keyboard = [[YourKeyboardViewController alloc]initWithNibName:@"nib file for keyboard" bundle:[NSBundle mainBundle]];

    keyboard.delegate = self;

  // connecting new keyboard to textfield
  someTextField.inputView = keyboard.view; 
}


-(void) buttonTapped: (int)ASCIICode;
{
    NSLog(@"you tapped button with %d", ASCIICode); 

}

这篇关于代码示例创建自己的键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆