Salut un code qui ressemble à ceciorientation iphone je n'ai pas travailler
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
username = [[UILabel alloc]initWithFrame:CGRectMake(53,115, 83, 21)];
username.text = @"Username";
[username setFont:[UIFont fontWithName:@"Arial" size:14]];
password = [[UILabel alloc]initWithFrame:CGRectMake(53,188, 75, 21)];
password.text = @"Password";
[password setFont:[UIFont fontWithName:@"Arial" size:14]];
txtusername = [[UITextField alloc]initWithFrame:CGRectMake(42, 144, 233, 31)];
[txtusername setBorderStyle:UITextBorderStyleRoundedRect];
[txtusername setPlaceholder:@"Username"];
[txtusername setAutocorrectionType:UITextAutocorrectionTypeNo];
txtusername.delegate = self;
txtusername.returnKeyType = UIReturnKeyDone;
txtpassword = [[UITextField alloc]initWithFrame:CGRectMake(42, 217, 233, 31)];
[txtpassword setBorderStyle:UITextBorderStyleRoundedRect];
[txtpassword setPlaceholder:@"Password"];
[txtpassword setAutocorrectionType:UITextAutocorrectionTypeNo];
txtpassword.delegate = self;
txtpassword.returnKeyType = UIReturnKeyDone;
loginbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[loginbutton setFrame:CGRectMake(110, 269, 124, 26)];
[loginbutton setTitle:@"Login" forState:UIControlStateNormal];
}
return self;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation currentOrientation = [[UIDevice currentDevice]orientation];
switch (currentOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
username.center = CGPointMake(157, 71);
password.center = CGPointMake(157,144);
txtusername.center = CGPointMake(146,100);
txtpassword.center = CGPointMake(120,172);
loginbutton.center = CGPointMake(214,225);
break;
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
username.bounds = CGRectMake(53, 115, 83, 21);
//username.center = CGPointMake(53, 115);
password.bounds = CGRectMake(53, 188, 75, 21);
//password.center = CGPointMake(53,188);
txtusername.center = CGPointMake(42,144);
txtpassword.center = CGPointMake(42,217);
loginbutton.center = CGPointMake(110,269);
break;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
Maintenant, ce qui semble être le problème est que l'interface ne s'orientée comme elle a trop, les composants ne viennent pas à la coordonnées comme je leur ai donné quand je fais tourner le matériel de l'iPhone à gauche et à droite, ils ne viennent pas à ces coordonnées, Lorsque ma vue se charge tout va bien, mais quand je tourne ma vue, je reçois ce bug. S'il vous plaît aidez-moi les gars Merci
Avez-vous essayé de vérifier quelle valeur vous obtenez de currentOrientation? J'ai eu des bugs avec l'orientation [[UIDevice currentDevice]] auparavant, et j'ai trouvé qu'il est préférable d'utiliser [self interfaceOrientation], en supposant que self est un UIViewController (ou une sous-classe). – Altealice
J'ai remplacé la ligne IInterfaceOrientation currentOrientation = [[UIDevice currentDevice] orientation]; avec UIInterfaceOrientation currentOrientation = [self interfaceOrientation]; – Radix