Zoom sur un champs de texte

Bonjour,



voila le problème, j'ai mis en place une vue via mon storyboard comprennent deux champs de texte. Le soucis est que une fois le curseur sur l'un de mes champs de texte, le claviers le recouvre largement. Du coup je voulais vous demandez comment mettre en place un système permettant de zoomer sur le champ de texte une fois le curseur dessus, a fin qu'il soit visible juste au dessus du clavier. Mais également qu'il dézoome une fois que le clavier disparaà®t.



Merci de votre aide

Réponses

  • AliGatorAliGator Membre, Modérateur
    Bonjour et bienvenue



    Tout est expliqué dans la doc Apple.



    Comme tu es nouveau, pense aussi à  aller te présenter dans la section "Présentation des Membres" du forum
  • santos44santos44 Membre
    juillet 2012 modifié #3
    Merci pour ta réponse.

    Du coup j'ai essayé de suivre la doc, mais j'y arrive pas.

    AppViewController.h:
    <br />
    <br />
    [color=#c72c25][color=#73492c]#import [/color]&lt;UIKit/UIKit.h&gt;[/color]<br />
    <br />
    [color=#7134aa][color=#b41ca4]@interface[/color][color=#000000] AppViewController : [/color]UIViewController[color=#000000]&lt;[/color]UIScrollViewDelegate[color=#000000],[/color]UITabBarDelegate[color=#000000]&gt;[/color][/color]<br />
    {<br />
    	[color=#b41ca4]IBOutlet[/color] [color=#7134aa]UITextField[/color] *adresse;<br />
    	[color=#b41ca4]IBOutlet[/color] [color=#7134aa]UITextField[/color] *login;<br />
    	[color=#b41ca4]IBOutlet[/color] [color=#7134aa]UITextField[/color] *password;<br />
    <br />
    [color=#7134aa]  UIView[/color] *activeField;<br />
      [color=#7134aa]UIScrollView[/color] *scrollView;<br />
    }<br />
    <br />
    [color=#b41ca4]@property[color=#000000] ([/color]nonatomic[color=#000000],[/color]retain[color=#000000]) [/color][color=#7134aa]UITextField[/color][color=#000000] *adresse;[/color][/color]<br />
    [color=#b41ca4]@property[color=#000000] ([/color]nonatomic[color=#000000], [/color]retain[color=#000000]) [/color][color=#7134aa]UITextField[/color][color=#000000] *login;[/color][/color]<br />
    [color=#b41ca4]@property[color=#000000] ([/color]nonatomic[color=#000000], [/color]retain[color=#000000]) [/color][color=#7134aa]UITextField[/color][color=#000000] *password;[/color][/color]<br />
    [color=#b41ca4]@property[color=#000000] ([/color]nonatomic[color=#000000], [/color]retain[color=#000000]) [/color][color=#7134aa]UITabBar[/color][color=#000000] *tabBar;[/color][/color]<br />
    <br />
    - ([color=#b41ca4]IBAction[/color])saisieReturn:([color=#b41ca4]id[/color])sender;<br />
    [color=#b41ca4]@end[color=#000000]
    
    [/color][/color]



    AppViewController.m:

    [/color][color=#73492c]#import [/color]&quot;AppViewController.h&quot;[/color]<br />
    <br />
    <br />
    [color=#578187][color=#b41ca4]@interface[/color][color=#000000] [/color]AppViewController[color=#000000] ()[/color][/color]<br />
    <br />
    [color=#b41ca4]@end[/color]<br />
    <br />
    [color=#b41ca4]@implementation[/color] AppViewController<br />
    [color=#b41ca4]@synthesize[color=#000000] adresse, login, password;[/color][/color]<br />
    <br />
    - ([color=#b41ca4]id[/color])initWithNibName:([color=#7134aa]NSString[/color] *)nibNameOrNil bundle:([color=#7134aa]NSBundle[/color] *)nibBundleOrNil<br />
    {<br />
    	[color=#b41ca4]self[/color] = [[color=#b41ca4]super[/color] [color=#401082]initWithNibName[/color]:nibNameOrNil [color=#401082]bundle[/color]:nibBundleOrNil];<br />
    	[color=#b41ca4]if[/color] ([color=#b41ca4]self[/color]) {<br />
    [color=#1c8600][color=#000000]		[/color]// Custom initialization[/color]<br />
    <br />
    	}<br />
    [color=#b41ca4][color=#000000]	[/color]return[color=#000000] [/color]self[color=#000000];[/color][/color]<br />
    }<br />
    <br />
    - ([color=#b41ca4]void[/color])viewDidLoad<br />
    {<br />
    [color=#401082][color=#000000]	[[/color][color=#b41ca4]super[/color][color=#000000] [/color]viewDidLoad[color=#000000]];[/color][/color]<br />
    [color=#401082][color=#000000]	[/color][color=#578187]tabBar[/color][color=#000000] = [[[/color][color=#7134aa]UITabBar[/color][color=#000000] [/color]alloc[color=#000000]] [/color]initWithFrame[color=#000000]:[/color]CGRectMake[color=#000000]([/color][color=#3d01d9]0[/color][color=#000000], [/color][color=#3d01d9]411[/color][color=#000000], [/color][color=#3d01d9]320[/color][color=#000000], [/color][color=#3d01d9]49[/color][color=#000000])];[/color][/color]<br />
    	[color=#578187]tabBar[/color].[color=#7134aa]delegate[/color] = [color=#b41ca4]self[/color];<br />
    	[[color=#b41ca4]self[/color].[color=#7134aa]view[/color] [color=#401082]addSubview[/color]:[color=#578187]tabBar[/color]];<br />
    [color=#7134aa][color=#000000]	[/color][color=#b41ca4]self[/color][color=#000000].[/color]navigationItem[color=#000000].[/color]title[color=#000000]=[/color][color=#c72c25]@&quot;Formulaire&quot;[/color][color=#000000];[/color][/color]<br />
    	// Do any additional setup after loading the view.<br />
    }<br />
    <br />
    - ([color=#b41ca4]void[/color])viewDidUnload<br />
    {<br />
    [color=#38595d][color=#000000]	[[/color][color=#b41ca4]self[/color][color=#000000] [/color]setAdresse[color=#000000]:[/color][color=#b41ca4]nil[/color][color=#000000]];[/color][/color]<br />
    	[[color=#b41ca4]self[/color] [color=#38595d]setLogin[/color]:[color=#b41ca4]nil[/color]];<br />
    [color=#38595d][color=#000000]	[[/color][color=#b41ca4]self[/color][color=#000000] [/color]setPassword[color=#000000]:[/color][color=#b41ca4]nil[/color][color=#000000]];[/color][/color]<br />
    [color=#401082][color=#000000]	[[/color][color=#b41ca4]super[/color][color=#000000] [/color]viewDidUnload[color=#000000]];[/color][/color]<br />
    [color=#1c8600][color=#000000]	[/color]// Release any retained subviews of the main view.[/color]<br />
    }<br />
    <br />
    [color=#1c8600]/////////////////////////////////////////[/color]<br />
    <br />
    - ([color=#b41ca4]void[/color])registerForKeyboardNotifications<br />
    {<br />
    [color=#000000]	[[[/color][color=#7134AA]NSNotificationCenter[/color][color=#000000] [/color][color="#401082"]defaultCenter[/color][color=#000000]] [/color][color="#401082"]addObserver[/color][color=#000000]:[/color][color=#B41CA4]self[/color] [color=#401082]selector[/color]:[color=#b41ca4]@selector[/color](keyboardWasShown:) [color=#401082]name[/color]:[color=#7134aa]UIKeyboardDidShowNotification[/color] [color=#401082]object[/color]:[color=#b41ca4]nil[/color]];<br />
    <br />
    [color=#000000]	[[[/color][color=#7134AA]NSNotificationCenter[/color][color=#000000] [/color][color="#401082"]defaultCenter[/color][color=#000000]] [/color][color="#401082"]addObserver[/color][color=#000000]:[/color][color=#B41CA4]self[/color] [color=#401082]selector[/color]:[color=#b41ca4]@selector[/color](keyboardWillBeHidden:)  [color=#401082]name[/color]:[color=#7134aa]UIKeyboardWillHideNotification[/color] [color=#401082]object[/color]:[color=#b41ca4]nil[/color]];<br />
    }<br />
    <br />
    <br />
    [color=#1c8600]- (void)keyboardWasShown:(NSNotification*)aNotification[/color]<br />
    [color=#1c8600]{[/color]<br />
    [color=#1c8600]	NSDictionary* info = [aNotification userInfo];[/color]<br />
    [color=#1c8600]	CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;[/color]<br />
    [color=#1c8600]	UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);[/color]<br />
    [color=#1c8600]	scrollView.contentInset = contentInsets;[/color]<br />
    [color=#1c8600]	scrollView.scrollIndicatorInsets = contentInsets;[/color]<br />
    [color=#1c8600]	// If active text field is hidden by keyboard, scroll it so it&#39;s visible[/color]<br />
    [color=#1c8600]	// Your application might not need or want this behavior.[/color]<br />
    [color=#1c8600]	CGRect aRect = self.view.frame;[/color]<br />
    [color=#1c8600]	aRect.size.height -= kbSize.height;[/color]<br />
    [color=#1c8600]	if (&#33;CGRectContainsPoint(aRect, password.frame.origin) ) {[/color]<br />
    [color=#1c8600]		CGPoint scrollPoint = CGPointMake(0.0, password.frame.origin.y-kbSize.height);[/color]<br />
    [color=#1c8600]		[scrollView setContentOffset:scrollPoint animated:YES];[/color]<br />
    [color=#1c8600]	}[/color]<br />
    [color=#1c8600]}[/color]<br />
    <br />
    - ([color=#b41ca4]void[/color])keyboardWillBeHidden:([color=#7134aa]NSNotification[/color]*)aNotification<br />
    {<br />
    [color=#7134aa][color=#000000]	[/color]UIEdgeInsets[color=#000000] contentInsets = [/color]UIEdgeInsetsZero[color=#000000];[/color][/color]<br />
    	[color=#578187]scrollView[/color].[color=#7134aa]contentInset[/color] = contentInsets;<br />
    	[color=#578187]scrollView[/color].[color=#7134aa]scrollIndicatorInsets[/color] = contentInsets;<br />
    }<br />
    <br />
    - ([color=#b41ca4]void[/color])textFieldDidBeginEditing:([color=#7134aa]UITextField[/color] *)textField<br />
    {<br />
       activeField = textField;<br />
    }<br />
    <br />
    - ([color=#b41ca4]void[/color])textFieldDidEndEditing:([color=#7134aa]UITextField[/color] *)textField<br />
    {<br />
    	[color=#578187]activeField[/color] = [color=#b41ca4]nil[/color];<br />
    }<br />
    [color=#1c8600]///////////////////////////////////////////////////[/color]<br />
    <br />
    - ([color=#b41ca4]BOOL[/color])shouldAutorotateToInterfaceOrientation:([color=#7134aa]UIInterfaceOrientation[/color])interfaceOrientation<br />
    {<br />
    [color=#b41ca4][color=#000000]	[/color]return[color=#000000] [/color]YES[color=#000000];[/color][/color]<br />
    }<br />
    <br />
    -([color=#b41ca4]IBAction[/color])saisieReturn:([color=#b41ca4]id[/color])sender<br />
    {<br />
    [color=#401082][color=#000000]	[sender [/color]resignFirstResponder[color=#000000]];[/color][/color]<br />
    }<br />
    <br />
    [color=#b41ca4]@end[/color][color=#b41ca4][color=#000000]
    




    Du coup quand j'affiche le clavier, rien se passe, il recouvre mon 3éme champ de texte, comme avant et j'arrive pas à  scroller pour y accéder.
  • Bonjour quelqu'un pour regarder un peu mon code ?
  • Tu devrais sûrement déclarer dans ton .h que ta classe implémente UITextFieldDelegate
Connectez-vous ou Inscrivez-vous pour répondre.