在纵向和横向带自动版式工作 [英] Working with AutoLayout in Portrait and Landscape

查看:174
本文介绍了在纵向和横向带自动版式工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自动调整版面,不如它,我都快疯了有约束。我在IB设计人像模式,但我不能获得所需的横向合作。

Auto Layout, as good as it is, driving me crazy with constraints. I have the portrait mode designed in IB but I can't get the desired landscape orientation to work.

注意,当方向将更改为景观,街区的UIImageView之间的间距减小和样品TEXT 更改为正确的文本对齐方式对齐。

Notice that when the orientation changes to landscape, the spacing between the UIImageView blocks decreases and the text alignment of SAMPLE TEXT changes to right aligned.

目前,我已经增加了一些限制为它工作。但是,我需要保持固定的UIImageView块之间的空间,其中,它会在肖像局促和景观精致的结果。我需要它为S $ P $垫出均匀地在纵向和COM preSS景观(如在上图中)。同样的,目前我的约束弹出文本,但它亘古不变的保持在屏幕右对齐的中心。

Currently, I have added a few constraints for it to work. However, I need to keep the space between UIImageView blocks fixed, as a result of which it looks cramped up in portrait and fine in landscape. I need it to be spread out evenly in portrait and compress in landscape (like in image above). Similarly, currently my constraints bring up the text but it doesnot keep it at the center of screen and right aligned.

这可能与自动布局呢?如果是这样,怎么样?大大有助于AP preciated。

Is this possible at all with Auto Layout? If so, how? Help greatly appreciated.

推荐答案

有几种方法可以解决这个。一种方法是附上3图像视图在一个UIView。得到的顶部和底部的图像视图约束的顶部和底部分别与给中间一一个centerY约束。给这个封闭视图一个固定的高度和宽度,以及约束到控制器的视图的顶部。让一个IBOutlet为此封闭鉴于高度约束,并改变它的旋转。在下面的例子中,我给它350的高度在纵向:

There are several ways to approach this. One way is to enclose your 3 image views in a UIView. Give the top and bottom image views constraints to the top and bottom respectively, and give the middle one a centerY constraint. Give this enclosing view a fixed height and width, and a constraint to the top of the controller's view. Make an IBOutlet to the height constraint for this enclosing view, and change it on rotation. In the example below, I gave it a height of 350 in portrait:

-(void)updateViewConstraints {
    [super updateViewConstraints];
    if (self.view.bounds.size.height < self.view.bounds.size.width) {
        self.heightCon.constant = self.view.bounds.size.height;
    }else{
        self.heightCon.constant = 350;
    }
}

至于标签,最简单的方法是去除你有约束(底部的centerX),并添加尾随和centerY轮换。

As for the label, the easiest way is to remove the constraints you have (bottom and centerX), and add trailing and centerY on rotation.

这篇关于在纵向和横向带自动版式工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆