IOS controls hide and disappear like Android

I used the storyboard with autolayout for my user interface design. Basically, Android has three different properties, for example Visible , Invisible, and Gone .

For example:

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); 

On iOS

Goal s

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

quick

  1) ? 2) CONTROLNAME.isHidden = true // used to hide the control but it will take space 

to perform the function Logged off to iOS. I searched on Google but cannot find a solution.

+12
android ios objective-c xcode autolayout swift
Mar 28 '14 at 6:01
source share
4 answers

To remove the space occupied by a view, you can either reduce the size its frame to zero, or remove it from the view hierarchy. That is, calling removeFromSuperview on the control.

For example, if you need to remove the space occupied by a UITextField (say CONTROLNAME ), 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 need to save an earlier size in order to return the control to its original position.

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

In the second case, you will need to save the frame of the control in order to return it to its original position (as well as the control itself, if it is a local variable or a weak instance variable).

 CONTROLNAME.frame = currentFrame; 
+5
Mar 28 '14 at 6:25
source share

if your idea is for example

 @property (weak, nonatomic) IBOutlet SearchBarView *searchBar; 

already has a limitation with it. Add a new IBLayout by dragging your restriction into the .h file.ex file:

 @property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintSearBarHeight; 

and do it whenever you want

 self.constraintSearBarHeight.constant = 0; 

if your submission has no limitation yet. I found this answer helpful. Just do below

 [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.searchBar attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]]; 
+2
Jul 28 '16 at 0:46
source share

Neither deleting the subvisor, nor setting the frame working for me as an alternative solution, I added a restriction programmatically that automatically corrects the difference.

For example: if you have 3 views, A_view B_view and C_view are vertically aligned in that order, and you want to β€œHide” B, and also adjust the difference, add a limit

 B_view.removeFromSuperView() var constr = NSLayoutConstraint(item: C_view, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: A_view, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 20) view.addConstraint(constr) 

constant (in this case) the amount of vertical space between C_view and A_view

He worked for me, but requires knowledge of the limitations

+1
Feb 25 '15 at 4:23
source share

You must create IBOutlets for each of the three subviews. Then you can show / hide each of them directly from these links. If you hide a view, it automatically hides its subviews.

 @IBOutlet var yourStackView: UIStackView! yourStackView.hidden = true; 

Another solution:

If you have tags for each view, you can hide and display them using:

Goal c

For concealment:

 [[self.view viewWithTag:1] setHidden:YES]; 

Showing:

 [[self.view viewWithTag:1] setHidden:NO]; 

In Swift:

Hiding:

 self.view.viewWithTag(1)?.hidden = true 

Showing:

 self.view.viewWithTag(1)?.hidden = false 

Note: This is just for covert viewing and not for reducing space. If you need to reduce space using hidden viewing, you need to limit the increase in magnification by hiding / showing programmatically. And the stack view does this automatically, where you simply change the actual height of the stack view using Hide / Show.

Maybe this will help you, otherwise you can ask me.

-one
Nov 08 '16 at 8:56
source share



All Articles