2010-12-12 60 views
2

J'ajoute manuellement un UIImageView à mon UIView et je le centre, cela fonctionne bien, mais après avoir fait tourner l'appareil, le UIImageView n'est plus centré (il est déplacé en bas à gauche). Comment puis-je réparer cela?UIImageView non centré après la rotation

logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wi-fi-sticker.png"]]; 
logoView.center = self.view.center; 
[self.view addSubview:logoView]; 

Cordialement, Sascha

+0

J'ai eu ce même problème maintenant, avez-vous résoudre ce problème? – jakev

+0

Désolé, je n'ai trouvé aucune solution, j'ai donc verrouillé l'écran. – Sascha

Répondre

4

j'ai pu centrer correctement le mien chaque fois en utilisant quelque chose comme ça

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration:{ 
     CGRect screen = [[UIScreen mainScreen] bounds]; 
     float pos_y, pos_x; 
     pos_y = UIDeviceOrientationIsLandscape(toInterfaceOrientation) ? screen.size.width/2 : screen.size.height/2; 
     pos_x = UIDeviceOrientationIsLandscape(toInterfaceOrientation) ? screen.size.height/2 : screen.size.width/2; 

     myImageView.center = CGPointMake(pos_x, pos_y); 
} 
+0

Ah génial, merci! – Sascha

+1

Vous pouvez simplement utiliser "toInterfaceOrientation" au lieu de [[UIDevice currentDevice] orientation] ". –

+0

@BenFlynn Mis à jour, bon oeil – jakev