ios - 旋转后 UIImageView 不居中
<p><p>我手动将 UIImageView 添加到我的 UIView 并将其居中,这工作正常,但是在旋转设备后, UIImageView 不再居中(它移动到左下角)。我该如何解决这个问题?</p>
<pre><code>logoView = [ initWithImage:];
logoView.center = self.view.center;
;
</code></pre>
<p>问候,
萨沙</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>每次使用这样的东西我都能正确地居中</p>
<pre><code>-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration:{
CGRect screen = [ 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);
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 旋转后 UIImageView 不居中,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/4424186/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/4424186/
</a>
</p>
页:
[1]