【问题标题】:keyBoard of textfield in iPhone- using alphanumeric chararacteriPhone中文本字段的键盘-使用字母数字字符
【发布时间】:2010-10-11 06:27:56
【问题描述】:

我是 iPhone 技术的新手,我想使用 TextField,但是当我使用键盘时,我不能使用字母数字字符。它仅适用于字母单词。

我用过的一些函数如下:-

-(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];
}

请帮我解决这个问题

谢谢 库纳尔

【问题讨论】:

  • 对不起,我不明白这个问题。有什么你想做却做不到的事?

标签: iphone


【解决方案1】:

XCode 文档中的 UIKeyboardType 是否对您有帮助(或者我误解了您的问题)?请注意,似乎有 3 种不同的数字键盘类型。

【讨论】:

  • 我想是的,当我使用分离类键盘应用程序时,该功能也不起作用。
  • 表示我也无法使用 tht 类更改字符。
猜你喜欢
  • 2012-07-25
  • 2011-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多