使用日语键盘时不调用UIKeyInput

时间:2012-08-18 07:54:04

标签: ios

我有一个继承自 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

当我使用英语或越南语键盘时,一切都是正确的。但是当我使用日语键盘时,会调用无事件,因此会抛出无异常。 我想我还没有达成一些协议

你能帮助我吗?

2 个答案:

答案 0 :(得分:4)

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

- (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 - 是调用以获取组合输入的所有字符的任何方法。您可以在文本未标记时发布通知(选择某种组合)。

答案 1 :(得分:0)

我已经解决了这个问题,此示例说明了如何在ios中将中文输入转换为insertText。

environment.cpp: In constructor 'environment::espacoFisico::espacoFisico()':
environment.cpp:95:51: error: invalid types '<unresolved overloaded function type>[long double]' for array subscript
                             this->tensor[buildingX][buildingY][buildingZ].emplace_back(globalTile());
                                               ^