iOS controls hide and gone like android

后端 未结 4 1561
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 09:05

I have used storyboard with autolayout for my UI design. Basically in android there are three different properties will be there like Visible, Invis

4条回答
  •  伪装坚强ぢ
    2021-01-04 09:37

    To remove the space occupied by a view(control) can either reduce the size of its frame to zero or remove it from the view hierarchy. I.e. by calling removeFromSuperview on the control.

    For example if you have to remove the space occupied by a UITextField (say CONTROLNAME), then you can either use:

    CGRect tempFrame = CONTROLNAME.frame;
    CGSize currentSize = tempFrame.size; //for later use
    tempFrame.size = CGSizeZero;
    CONTROLNAME.frame = tempFrame;
    

    or

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

    UPDATE:

    In the first case you will have to store the earlier size to bring back the control to its initial position.

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

    In the second case you will have to store the frame of the control to bring it back to its initial position (and also the control itself if it is a local variable or weak instance variable).

    CONTROLNAME.frame = currentFrame;
    

提交回复
热议问题