gpt4 book ai didi

ios - UIImageView 旋转后不居中

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:52:25 25 4
gpt4 key购买 nike

我手动将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com