X code。与自动布局不是让我来移动物体origin.y值故事板问题 [英] Xcode storyboard issue with auto layout not allowing me to move an objects origin.y value

查看:188
本文介绍了X code。与自动布局不是让我来移动物体origin.y值故事板问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的故事板我刚刚实施了补充完善约束我的元素大小类,但试图修改这些元素y位置位于把它移到了键盘上的show事件以便它显示连接到键盘类似的,元素不动,因为限制的。我曾尝试删除这些约束,这并没有帮助。从我读过我的理解是,如果没有限制,有应用程序是建立一些时产生的。我如何用编程方式移动可以看到这里的元素:i.imgur.com/uHfgEKl.png。我问我怎么移动元素y位置上的故事板与键盘的大小,而大小类启用?如果有谁知道怎么样,请通知我。
遗憾的最后一个环节是不是超链接,我没有信誉为我新的堆栈溢出。

In my storyboard I have just implemented size classes which added perfect constraints to my elements but when trying to modify where the elements y position is located to move it up on the keyboard show event so that it appears attached to the keyboard like this, the elements don't move at all because of the constraints. I have tried removing the constraints, which did not help. From what I've read my understanding of it is if there are no constraints, there are some generated when the app is built. How I used to programmatically move the elements can be seen here: i.imgur.com/uHfgEKl.png . I am asking how do I move the elements y position on the storyboard up with the size of the keyboard while size classes are enabled? If anyone knows how, please inform me. Sorry the last link is not hyperlinked, I have no reputation as I am new to stack overflow.

推荐答案

试试这个:


  1. 添加的的垂直空间约束的为你的项目,然后从屏幕底部针它的距离不变。在界面生成器的,请将您的物品靠近屏幕的底部,选择它,然后选择自动布局引脚图标<大骨节病> | - [] - | 和底部转支撑。将常量设置你想要的初始值。点击<大骨节病>添加1约束

  1. Add a Vertical Space Constraint for your item and pin it a constant distance from the bottom of the screen. In Interface Builder, place your item near the bottom of the screen, select it, and then select the Auto Layout Pin icon |-[]-| and turn on the bottom strut. Set the constant to the initial value you want. Click Add 1 Constraint.

@IBOutlet 来约束添加在code。

Add an @IBOutlet to the constraint in your code.

@IBOutlet weak var verticalSpaceConstraint: NSLayoutConstraint!

您可以通过<大骨节病>控制从约束拖动的文档版式视图的到你的ViewController code。

You can do this by Control dragging from the constraint in the Document Layout View to your ViewController code.

当您需要将您的项目,将

When you need to move your item, change constant

// Move my item up 100 points
verticalSpaceConstraint.constant += 100


如果您要进行动画约束变化:


If you want to animate the constraint change:

    self.view.layoutIfNeeded()
    verticalSpaceConstraint.constant += 100
    UIView.animateWithDuration(2.0) {
        self.view.layoutIfNeeded()
    }

这篇关于X code。与自动布局不是让我来移动物体origin.y值故事板问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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