2010-12-12 99 views
2

我手动添加一个UIImageView到我的UIView和居中它,这工作正常,但旋转设备后,UIImageView不居中了(它被移动到左下角)。我怎样才能解决这个问题?UIImageView不居中后旋转

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

问候, 萨沙

+0

我现在已经得到了同样的问题每次都正确居中矿,你有没有解决? – jakev 2011-01-17 23:28:52

+0

对不起,我没有找到任何修复,所以我锁定了屏幕。 – Sascha 2011-04-03 12:48:00

回答

4

我能够使用这样的事情

-(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

啊太好了,谢谢! – Sascha 2011-04-04 19:53:36

+1

您可以使用“toInterfaceOrientation”而不是[[UIDevice currentDevice]方向]“。 – 2012-07-08 02:04:14

+0

@BenFlynn更新,好眼睛 – jakev 2013-07-15 17:35:42