2017-08-09 3 views
0

Utilisation iPad contrôleur de vue partagé:défile textfield avec le code mais revient immédiatement à la position d'origine

(IBAction) textfieldEditingDidBeginAction:(id)sender{ 
     CGPoint scrollPoint = CGPointMake(0.0, 40); 
     [_scroller setContentOffset:scrollPoint animated:YES]; 
    } 

Le défile champ de texte 40, mais après le clavier apparaît, il revient à la position précédente. Cela ne se produit pas avec le même code dans la vue portrait d'iPhone. ?? Aussi cela ne semble se produire que pour le premier champ de texte, le suivant fonctionne et revient au premier il fonctionne alors.

Répondre

0

Le problème est avec l'iPad en mode paysage, il ajuste automatiquement le champ de texte après le défilement ci-dessus. Afin de faire défiler avec des montants différents dans l'orientation du paysage iPad j'ai utilisé ce qui suit qui fonctionne:

Boolean keyboardIsShown; 
    UITextField *currentTextField; 

    - (void)keyboardWasShown:(NSNotification*)aNotification){ 
    if(keyboardIsShown) 
     return; 
    [self scrollipadTextField]; 
    keyboardIsShown = yes; 
    } 

    -(IBAction) textfieldAEditingDidBegin:(id)sender{ 
     currentTextField=sender; 
     if(keyboardIsShown) 
      [self scrollipadTextField]; 

    } 
    -(void)scrollipadTextField{ 
     int amount; 
     if([[UIDevice currentDevice] userInterfaceIdiom]== 
      userInterfaceIdiomPad &&([[UIApplication sharedApplication] 
      statusBarOrientation]==UIInterfaceOrientationLandscapeRight 
      ||[[UIApplication sharedApplication] statusBarOrientation]== 
      UIInterfaceOrientationLandscapeLeft)){ 
       if(currentTextField==_TextFieldA) 
        amount=70; 
       if(currentTextField==_TextFieldB) 
        amount=90;//etc. 
       CGPoint scrollPoint = CGPointMake(0.0, amount); 
       [_scroller setContentOffset:scrollPoint animated:YES]; 
      } 
     }