简体   繁体   English

具有自动布局的iOS旋转

[英]The iOS rotation with auto layout

I just followed Swift Ios tutorial on Itunes (Stanford University CS193p) 我刚刚遵循了Itunes上的Swift Ios教程(斯坦福大学CS193p)

I followed the first example to make a calculator. 我按照第一个示例制作了一个计算器。

1.I add the button to the screen and set the auto layout attributes. 1.我将按钮添加到屏幕并设置自动布局属性。

在此处输入图片说明

2.then the warning comes out, and I update the frames with the constraints. 2.然后发出警告,我用约束条件更新框架。

在此处输入图片说明

3.The I start the simulator, it seems works fine. 3.我启动了模拟器,看来工作正常。

在此处输入图片说明

  1. But when I rotated the screen, all the number buttons get to heap together. 但是,当我旋转屏幕时,所有数字按钮都会堆积在一起。

在此处输入图片说明

I know it must be made by some small mistakes, even I carefully followed the tutorial. 我知道一定是由一些小错误造成的,即使我认真地遵循了本教程。 Because I am new to ios, and thought this problem is really hard to describe, so I just put it there. 因为我是ios的新手,并且认为这个问题真的很难描述,所以我就把它放在那儿了。 Hopefully, there is some one could solve this problem. 希望有一些人可以解决这个问题。

You have this problem because you made the constraints using the wAny hRegular size class. 您有此问题,因为您使用wAny hRegular size类进行了约束。 When you rotate to landscape, the height is now compact, and you don't have any constraints for that size class (so all the buttons have {0,0} origin). 旋转到横向时,高度现在紧凑了,并且该尺寸类别没有任何约束(因此所有按钮的原点为{0,0})。 You should make separate constraints for that size class, probably with 3 rows of 4 rather than 4 rows of 3 to fit the shorter space better. 您应该对该大小类进行单独的约束,可能使用3行4行,而不是4行3行以更好地适应较短的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM