ios - UIImageView 旋转后不居中

标签 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];

问候, 萨沙

最佳答案

每次使用这样的东西我都能正确居中

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

相关文章:

objective-c - 调整 UIImageView 数组中单个图像的大小

swift - 使用控件在 Swift 中调整图像大小的最佳方法是什么?

javascript - 为什么我的水箱无法正常旋转?

r - 为什么矩阵到栅格显示旋转?

java - 将手机锁定为纵向模式

iphone - 如何在iOS中实现c++ setRGB

iphone 模型返回零?

ios - 如何弹出消息通知用户?

ios - 是否可以检测 iPhone 何时打开?

ios - iPad 2 UIImageview 显示图像不正确(渲染不正确)