0

したがって、約7つのテキストフィールドがあり、そのうち6つはキーボードを使用し、もう1つはピッカーを使用します. 私が抱えている問題は、ピッカーにリンクされているテキストフィールドに触れたときにキーボードが開いていると、キーボードが消えず、ピッカーがその下に表示されることです。これが私のコードです

- (void) textFieldDidBeginEditing:(UITextField *)textField
 {    
pickerView.hidden = YES;
if ([textField isEqual:state])
{   

    [state resignFirstResponder];
    [self textFieldFirstResponderOnDelay1];




}

else
{
    pickerView.hidden = YES;

    // This movie the view up so textfield isn't hidden by keyboard
    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];

}





}


-(void) viewDidLoad
{
pickerView = [[UIPickerView alloc] init];
pickerView.frame = CGRectMake(0, 245, 320, 216);
pickerView.delegate = self;
pickerView.hidden = YES;
pickerView.showsSelectionIndicator = YES;
state.inputView = pickerView;

[self.view addSubview:pickerView];
}


-(void)textFieldFirstResponderOnDelay1
{ 
pickerView.hidden=NO;
[pickerView reloadAllComponents];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
if([textField isEqual:state])
{

}
else
{
    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];

}




}
4

1 に答える 1

2

メインウィンドウのサブビューとしてピッカービューを追加する代わりに、適切なテキストビューの入力ビューとして設定するだけで、キーボードが通常行うように表示/非表示になります。

textField.inputView = pickerView;
于 2012-06-26T17:15:46.780 に答える