我手动将 UIImageView 添加到我的 UIView 并将其居中,这工作正常,但是在旋转设备后, UIImageView 不再居中(它移动到左下角)。我该如何解决这个问题?
logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed"wi-fi-sticker.png"]];
logoView.center = self.view.center;
[self.view addSubview:logoView];
问候,
萨沙
Best Answer-推荐答案 strong>
每次使用这样的东西我都能正确地居中
-(void)willAnimateRotationToInterfaceOrientationUIInterfaceOrientation)toInterfaceOrientation durationNSTimeInterval)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/
|