旋转后UIImageView不居中

时间:2010-12-12 21:38:14

标签: ios uiimageview rotation

我手动将UIImageView添加到我的UIView并将其居中,这很好用,但在旋转设备后,UIImageView不再居中(它移动到左下角)。我该如何解决这个问题?

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

此致 的Sascha

1 个答案:

答案 0 :(得分: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);
}