2010-10-11 27 views
1

我是iPhone新手,我想使用TextField,但是當我使用鍵盤時,我無法使用字母數字字符。它只適用於字母詞。iPhone中使用字母數字字符的textfield keyBoard

我用的一些功能如下: -

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField { 

    if(theTextField == txtanswer) { 
    [txtanswer resignFirstResponder]; 
    } 
    return YES; 
} 



- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    CGRect textFieldRect = 
    //[self.view.window convertRect:textField.bounds fromView:textField]; 
    CGRect viewRect = 
    //[self.view.window convertRect:self.view.bounds fromView:self.view]; 
    CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height; 
    CGFloat numerator = 
    midline - viewRect.origin.y 
    - MINIMUM_SCROLL_FRACTION * viewRect.size.height; 
    CGFloat denominator = 
    (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) 
    * viewRect.size.height; 
    CGFloat heightFraction = numerator/denominator; 
    if (heightFraction < 0.0) 
    { 
     heightFraction = 0.0; 
    } 
    else if (heightFraction > 1.0) 
    { 
     heightFraction = 1.0; 
    } 

    UIInterfaceOrientation orientation = 
    [[UIApplication sharedApplication] statusBarOrientation]; 
    if (orientation == UIInterfaceOrientationPortrait || 
     orientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction); 
    } 
    else 
    { 
     animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction); 
    } 

    CGRect viewFrame = self.view.frame; 
    viewFrame.origin.y -= animatedDistance; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION]; 

    [self.view setFrame:viewFrame]; 

    [UIView commitAnimations]; 
} 

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    if(cehc==2) 
    { 


    }if(textField == txtanswer) 

    [txtanswer resignFirstResponder]; 
    return YES; 
} 
-(IBAction) textFieldDoneEditing : (id) sender{ 
    CGRect viewFrame = self.view.frame; 
    viewFrame.origin.y += animatedDistance; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION]; 

    [self.view setFrame:viewFrame]; 

    [UIView commitAnimations]; 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField; 
{ 
    CGRect viewFrame = self.view.frame; 
    viewFrame.origin.y += animatedDistance; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION]; 

    [self.view setFrame:viewFrame]; 

    [UIView commitAnimations]; 
} 

請幫我解決這個問題

感謝 注:Kunal

+0

對不起,我不明白這個問題。你試圖做什麼,你做不到? – jrturton 2011-11-03 08:10:37

回答

0

不UIKeyboardType在Xcode文檔幫助您(或做我誤解你的問題)?請注意,似乎有3種不同的數字鍵盤類型。

+0

我認爲是的,當我使用分離類的deffrent鍵盤應用程序時,該功能也dosn't工作。 – 2010-10-11 09:14:57

+0

意味着我不能改變使用該課程的角色。 – 2010-10-11 09:16:10