IOS cotrols隐藏,像android一样

前端之家收集整理的这篇文章主要介绍了IOS cotrols隐藏,像android一样前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的UI设计使用了autolayout的故事板.基本上在 android中有三种不同的属性将会像Visible和Invisible那样消失.

例如:

  1. 1) android:visibility="gone" // used to hide the control and as well as space
  2. (or)
  3. CONTROLNAME.setVisibility(View.GONE);
  4. 2) android:visibility="invisible" // used to hide the control but it will take space
  5. (or)
  6. CONTROLNAME.setVisibility(View.INVISIBLE);

在IOS中,

  1. 1) ?
  2. 2) [CONTROLNAME setHidden:TRUE]; // used to hide the control but it will take space

在IOS中我已经从谷歌搜索,但我无法找到解决方案.

解决方法

删除视图(控件)占用的空间,可以将其框架的大小减小到零,或者将其从视图层次结构中移除.即通过调用控件上的removeFromSuperview.

例如,如果您必须删除UITextField占用的空间(例如CONTROLNAME),则可以使用:

  1. CGRect tempFrame = CONTROLNAME.frame;
  2. CGSize currentSize = tempFrame.size; //for later use
  3. tempFrame.size = CGSizeZero;
  4. CONTROLNAME.frame = tempFrame;

要么

  1. CGRect currentFrame = CONTROLNAME.frame; //for later use
  2. [CONTROLNAME removeFromSuperview];

更新:

在第一种情况下,您将必须存储较早的大小以将控件恢复到其初始位置.

  1. CGRect tempFrame = CONTROLNAME.frame;
  2. tempFrame.size = currentSize; //set to initial value
  3. CONTROLNAME.frame = tempFrame;

在第二种情况下,您将必须存储控件的框架以使其恢复到其初始位置(以及控件本身,如果它是局部变量或弱实例变量).

  1. CONTROLNAME.frame = currentFrame;

猜你在找的iOS相关文章