質問

I have three views that are in a horizontal line. The middle view is centered horizontally while the other two are the same distance away, one to the left and one to the right.

When I rotate the screen to landscape, I want the middle view to stay centered horizontally, and I want the other two views to stay the same distance away from the center.

Is there an easy way to do this in Xcode?

役に立ちましたか?

解決

This is harder to do with springs & struts and setting the frame, and is simpler to handle with Auto Layout constraints, if you can use those in your app. See this video from Justin Williams for a good overview of why.

If you need to stick with springs & struts and setting the frame in code, for some reason, you'll have to recompute the center of the super view, and then use that to set the .center of your subview.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top