iOS下86版五笔输入法练习程序(作为备忘,最基本功能的演示demo,版本:0.99版)

以下是一个前期的基本功能思路仅作为备忘(这段代码只是前期一个demo,只是针对字母编码的一个业务逻辑,只是一个大体的思路,后期的改良基本上推翻了前期所有的代码,但是前期的代码中的思想仍然得到保留),正式版已经完成,由于经过多次改良后代码过多这里就不放出来了,正式版的代码经过改良后打英文表示五笔编码,打其它字符或者数字时直接上屏,在输入编码后再选数字表示选择提示字上屏,与真实pc端输入法达到一样的效果。

- (void)tfWrite {

    NSMutableString *tmp = [NSMutableStringstring];

    NSString *strLow = [self.tf.textlowercaseString];

    tmp = [[NSMutableString alloc] initWithFormat:strLow,nil];

    unichar cc;

    if (tmp.length >=1) {

        cc = [tmp characterAtIndex:tmp.length-1];

    }

    NSLog(@"cc:%c",cc);

    if ((cc >= '1' && cc <='5') || (cc >='a' && cc <='z') || cc ==' ') {

        if (1 ==self.tf.text.length && cc >='1' && cc <= '5') {

            self.tf.text =@"";

        }

        if (self.tf.text.length >=2 && (cc >='1' && cc <='5')) {

            int indexTmp = [[NSNumbernumberWithUnsignedChar:cc]intValue]-'0';

            NSLog(@"indexTmp:%d",indexTmp);

            self.tf.text =@"";

            if (self.wordTmp ==nil) {

                self.wordLabel.text = [self.wordArray[indexTmp-1]copy];

            }else{

                self.wordLabel.text = [self.wordTmpstringByAppendingString:[self.wordArray[indexTmp-1]copy]];

            }

            self.wordTmp = [self.wordLabel.textcopy];

        }

        if (4 ==self.tf.text.length && (cc >='a' && cc <= 'z')) {

            self.states =YES;

        }

        if (5 ==self.tf.text.length && (cc >='a' && cc <= 'z')) {

            self.tf.text =@"";

            if (self.wordArray.count >0) {

                if (self.wordTmp ==nil) {

                    self.wordLabel.text = [self.wordArray[0]copy];

                }else{

                    self.wordLabel.text = [self.wordTmpstringByAppendingString:[self.wordArray[0]copy]];

                }

            }

            self.wordTmp = [self.wordLabel.textcopy];

        }

        if (cc == ' ') {

            if (self.tf.text.length ==1) {

                self.tf.text =@"";

                return;

            }

            self.tf.text =@"";

            if (self.wordTmp ==nil) {

                self.wordLabel.text = [self.wordArray[0]copy];

            }else{

                self.wordLabel.text = [self.wordTmpstringByAppendingString:[self.wordArray[0]copy]];

            }

            self.wordTmp = [self.wordLabel.textcopy];

        }

    }else {

        self.tf.text =@"";

    }

    if (0 !=self.wordArray.count &&0 !=self.keyArray.count) {

        [self.wordArrayremoveAllObjects];

        [self.keyArrayremoveAllObjects];

    }

    for (int i =0; i <self.allKey.count; i++) {

        if ([self.allKey[i]hasPrefix:[self.tf.textlowercaseString]]) {

            [self.wordArrayaddObject:self.allWord[i]];

            [self.keyArrayaddObject:self.allKey[i]];

            //暂时只提示5

            if (5 ==self.wordArray.count) {

                break;

            }

        }

    }

    if (self.states) {

        if (1 ==self.wordArray.count) {

            self.tf.text =@"";

            if (self.wordTmp ==nil) {

                self.wordLabel.text = [self.wordArray[0]copy];

            }else{

                self.wordLabel.text = [self.wordTmpstringByAppendingString:[self.wordArray[0]copy]];

            }

            self.wordTmp = [self.wordLabel.textcopy];

            self.states =NO;

        }

    }

    [self.tableViewreloadData];

}



iOS下86版五笔输入法练习程序(作为备忘,最基本功能的演示demo,版本:0.99版)_第1张图片




iOS下86版五笔输入法练习程序(作为备忘,最基本功能的演示demo,版本:0.99版)_第2张图片



你可能感兴趣的:(ios开发,五笔输入法,86wb)