Constraints messing me up

2019-08-16 07:02发布

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. Setup

Constraints

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-16 07:40

Remove the Auto - layout like this.

enter image description here

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.

查看更多
登录 后发表回答