gpt4 book ai didi

ios - 使用日语键盘时不调用 UIKeyInput

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:21 27 4
gpt4 key购买 nike

我有一个继承自 UIView 并符合 UIKeyInput 的类*.h*

@interface UIKeyInputExampleView : UIView  <UIKeyInput>{
NSMutableString *textStore;
}

@property (nonatomic, retain) NSMutableString *textStore;

@end

.m

@implementation UIKeyInputExampleView

@synthesize textStore;

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
self.textStore = [NSMutableString string];
[self.textStore appendString:@"Touch screen to edit."];

self.backgroundColor = [UIColor whiteColor];
}
return self;
}

- (void)dealloc {
[textStore dealloc];
[super dealloc];
}

#pragma mark -
#pragma mark Respond to touch and become first responder.

- (BOOL)canBecomeFirstResponder { return YES; }
-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {
[self becomeFirstResponder];
}

#pragma mark -
#pragma mark Drawing

- (void)drawRect:(CGRect)rect {
CGRect rectForText = CGRectInset(rect, 20.0, 20.0);
UIRectFrame(rect);
[self.textStore drawInRect:rectForText withFont:[UIFont fontWithName:@"Helvetica" size:24.0f]];
}

#pragma mark -
#pragma mark UIKeyInput Protocol Methods

- (BOOL)hasText {
if (textStore.length > 0) {
return YES;
}
return NO;
}

- (void)insertText:(NSString *)theText {
NSLog(@"Text have just enter:%@ length=%d ascii=%d",theText,theText.length,[theText characterAtIndex:0]);
if ([theText isEqualToString:@"\n"]) {
NSLog(@"Enter have just pressed!");
[self resignFirstResponder];
}
self.textStore = (NSMutableString*)theText;
[self setNeedsDisplay];
}

- (void)deleteBackward {
self.textStore = (NSMutableString*)@"delete";
[self setNeedsDisplay];
}

@end

当我使用英语或越南语键盘时,一切正常。但是当我使用日语键盘时,没有事件被调用,没有异常被抛出。我想我没有遵守某些协议(protocol)

你能帮帮我吗?

最佳答案

花了一些时间,但终于成功了。
1. 对于单个字符 - 我仍然使用 UIKeyInput 协议(protocol)。
2. 对于东亚语言,我使用 NSString 属性 intlInput 来获取所有输入字符。以下是允许执行此操作的 UITextInput 协议(protocol)的两种方法。

- (void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange {
self.intlInput = markedText;
}
- (void) unmarkText {
if (!self.intlInput) return;
for (int i=0;i<self.intlInput.length;i++) {
[self sendChar:[self.intlInput characterAtIndex:i]];
}
self.intlInput = nil;
}

sendChar - 是调用以获取组合输入的所有字符的任何方法。您可以在文本未标记(选择了某些组合)时发布通知。

关于ios - 使用日语键盘时不调用 UIKeyInput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12016928/

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