gpt4 book ai didi

iphone - 创建自己的键盘的代码示例

转载 作者:行者123 更新时间:2023-12-01 18:01:56 24 4
gpt4 key购买 nike

很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .




10年前关闭。




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

请帮帮我

最佳答案

你的键盘.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

你的键盘.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]];
}
}

现在 - 使用您想要的任何 View 制作您自己的 .xib 文件。使用“buttonTapped”方法连接每个按钮。为每个按钮分配适当的 ASCII 代码作为标签。我正在使用这个解决方案,一切正常。

用法:
您正在将 View Controller 创建为 YourKeyboardControllerDelegate。
@interface MainViewController : UIViewController <YourKeyboardControllerDelegate> 
{
YourKeyboardViewController *keyboard
}

并在 .m 文件中
- (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);

}

关于iphone - 创建自己的键盘的代码示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8323928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com