我的UI设计使用了autolayout的故事板.基本上在
android中有三种不同的属性将会像Visible和Invisible那样消失.
例如:
- 1) android:visibility="gone" // used to hide the control and as well as space
- (or)
- CONTROLNAME.setVisibility(View.GONE);
- 2) android:visibility="invisible" // used to hide the control but it will take space
- (or)
- CONTROLNAME.setVisibility(View.INVISIBLE);
在IOS中,
- 1) ?
- 2) [CONTROLNAME setHidden:TRUE]; // used to hide the control but it will take space
解决方法
要删除视图(控件)占用的空间,可以将其框架的大小减小到零,或者将其从视图层次结构中移除.即通过调用控件上的removeFromSuperview.
例如,如果您必须删除UITextField占用的空间(例如CONTROLNAME),则可以使用:
- CGRect tempFrame = CONTROLNAME.frame;
- CGSize currentSize = tempFrame.size; //for later use
- tempFrame.size = CGSizeZero;
- CONTROLNAME.frame = tempFrame;
要么
- CGRect currentFrame = CONTROLNAME.frame; //for later use
- [CONTROLNAME removeFromSuperview];
更新:
在第一种情况下,您将必须存储较早的大小以将控件恢复到其初始位置.
- CGRect tempFrame = CONTROLNAME.frame;
- tempFrame.size = currentSize; //set to initial value
- CONTROLNAME.frame = tempFrame;
在第二种情况下,您将必须存储控件的框架以使其恢复到其初始位置(以及控件本身,如果它是局部变量或弱实例变量).
- CONTROLNAME.frame = currentFrame;