限制弄乱我 [英] Constraints messing me up

查看:354
本文介绍了限制弄乱我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个按钮,在视图的右侧对齐。我有一个方法,它接受发送者(按钮)的框架,创建一个UIImageView框架,删除发件人从超级视图,并添加在该位置的imageView,它的工作除了那些约束困惑我。 >

看来,当我删除一个按钮,它改变了所有的其他人的大小,我不能解释为什么。



我只想删除自动布局功能,但我想为iPhone 5和iPhone 4屏幕尺寸的应用程序。



我在这里做什么?



简短:
我有一个视图上有5个按钮,一个方法创建一个UIImageView与发件人按钮框架,删除按钮和在该位置添加img视图。工程,但改变1个按钮后所有其他按钮的大小改变。如何防止这种情况?我认为这是因为它们以对的方式彼此对齐。



感谢




我的设置和约束的图像,不知道哪一个给我的问题,但也许底部一个,因为它链接到其他按钮。我不想让我的按钮改变大小,如果我以编程方式删除其中之一,这是发生了什么。



解决方案

删除自动 - 布局这样。



>



然后使用Bounds属性获取不同iPhone的高度,然后以各自的方式设置框架。



通过检查

  if([[UIScreen mainScreen] bounds] .size.height == 568)
{
// newer iphone
}
else
{
//旧的iphones
}

新编辑:



所以你真正需要的是删除第一个按钮和SEcond Button之间的PADDING。 / p>

您必须将其删除,然后根据Y轴从顶部对齐每个视图。
这将完成这项工作。


I have 5 buttons, aligned in the right side of the view. I have a method, that takes the frame of the sender (the button), creates a UIImageView with that frame, removes sender from superview and add the imageView at that location, and it works EXCEPT that those constraints mess me up.

It seems like when i remove one of the buttons, it changes the size of all the others, and i cant explain why.

I would love to simply just remove the auto-layout feature, but i would like to make the app for both iPhone 5 and iPhone 4 screen sizes.

So what do i do here?

IN SHORT: I have 5 buttons on a view, a method creates a UIImageView with the sender buttons frame, remove button and add img view at that location. Works, but after changing 1 button the size of all the other buttons change. How to prevent this? i think it is because they are aligned to each other in "pairs".

Thanks

// EDIT Images of my setup and the constraints, not sure which one is giving me problems but maybe the bottom one, since it is linked to the other buttons. i DONT want my buttons to change size if i programmatically remove one of them, and that is whats happening.

解决方案

Remove the Auto - layout like this.

Then use the Bounds property for getting heights for different iPhones and then set the frames in respective way.

You can get the height by checking

 if([[UIScreen mainScreen] bounds].size.height == 568)
 {
         //newer iphone
 }
 else
 {
         //older iphones
 }

NEW EDIT :

So what you actually need is to remove the PADDING between the First Button and SEcond Button.

You have to remove it and then align every View with respect to Y-Axis from top. This would do the job.

这篇关于限制弄乱我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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