相当于iOS版为Android View.GONE知名度模式 [英] iOS equivalent for Android View.GONE visibility mode

查看:331
本文介绍了相当于iOS版为Android View.GONE知名度模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发适用于iOS的应用程序,我使用的是自动版式上的脚本。我的一个观点控制器有一组4个按钮,在某些情况下,我想先做出一家消失。

如果我使用 setHidden:TRUE 法的UIButton成为无形的,但它仍然很明显需要空间的看法,其结果是一个洞我已经未能填充使得其余的UIButton浮起朝着主视图的顶部。

在Android的我就只是简单地使用 View.GONE 而不是 View.INVISIBLE ,但在iOS的我米仍坚持这一行为,我不想相信,唯一的解决办法就是手动(是我的意思是编程)移动剩余的元素的顶端。

我想我已经能够做到这一点的设置某种约束,使一切自动,因为它是在Android的,但我有没有运气。

我把自动布局起飞前,有人可以点我朝着正确的方向?

我使用的是IB,但我舒服的纲领性的东西为好。

更新:

元件高度设置为0,不能很好的帮助。

我想是这样的:

 的UIButton * B;
的CGRect frameRect = b.frame;
frameRect.size.height = 0;
b.frame = frameRect;


解决方案

添加,设置视图的高度为0约束(NSLayoutAttributeHeight)为我工作:

  [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.captchaView属性:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:无属性:NSLayoutAttributeNotAnAttribute乘数:1.0不变:0];

I'm developing an app for iOS and I'm using the Storyboard with AutoLayout ON. One of my view controllers has a set of 4 buttons, and in certain circumstances i would like to make the first one disappear.

If I use the setHidden:TRUE method the UIButton become invisible but it still obviously take space in the view, and the result is an "hole" which I've not been able to fill making the remaining UIButton to float towards the top of the main view.

In Android I would have simply used View.GONE instead of View.INVISIBLE, but in iOS I'm stuck with this behaviour and I don't want to believe that the only solution is to manually (yes I mean programmatically) move the remaining elements to the top.

I thought I would have been able to do it setting some sort of Constraint to make everything as automatic as it is in Android but I've had no luck.

Before I turn Autolayout OFF, can someone point me to the right direction?

I'm using the IB, but I'm comfortable with programmatic stuff as well.

UPDATE:

Setting the component height to 0 doesn't help as well.

I tried something like this:

UIButton *b;
CGRect frameRect = b.frame;
frameRect.size.height = 0;
b.frame = frameRect;

解决方案

Adding a constraint(NSLayoutAttributeHeight) that sets height of the view to 0 worked for me:

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.captchaView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]];

这篇关于相当于iOS版为Android View.GONE知名度模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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