我手动将 UIImageView 添加到我的 UIView 并将其居中,这工作正常,但旋转设备后,UIImageView 不再居中(它移至左下角)。我该如何解决这个问题?
logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wi-fi-sticker.png"]];
logoView.center = self.view.center;
[self.view addSubview:logoView];
问候, 萨沙
最佳答案
每次使用这样的东西我都能正确居中
-(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);
}
关于ios - UIImageView 旋转后不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4424186/