ios - Swift how to hide element and his space -


i hope title clear. want hide element (data picker in case) , want hide space. tried animation:

    @ibaction func showqnt(sender: anyobject) {     if (self.pickerqnt.alpha == 0.0){         uiview.animatewithduration(0.2, delay: 0.0, options: uiviewanimationoptions.showhidetransitionviews, animations: {             self.pickerqnt.alpha = 1.0               }, completion: {                 (finished: bool) -> void in                 //var consth = nslayoutconstraint(item: self.pickerqnt, attribute: nslayoutattribute.height, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: 162)                 //self.pickerqnt.addconstraint(consth)         })     } else {         uiview.animatewithduration(0.2, delay: 0.0, options: uiviewanimationoptions.showhidetransitionviews, animations: {             self.pickerqnt.alpha = 0.0               }, completion: {             (finished: bool) -> void in                 // check: ?!? constrain set view height 0 run time                 //var consth = nslayoutconstraint(item: self.pickerqnt, attribute: nslayoutattribute.height, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: 0)                 //self.pickerqnt.addconstraint(consth)         })     } } 

i've tried like:

self.pickerqnt.hidden = true 

but wont work.

thanks in advance.

using "hidden" property on views in objective-c/swift matter of fact not "collapse" space view taking (as opposed "view.gone" in android).

instead should use autolayout , height constraint.

create height constraint in xib/storyboard file. giving wished height. make iboutlet constraint (ctrl-drag constraint in constraints list source file), , can write method

swift solution

var pickerheightvisible: cgfloat! ... ... func togglepickerviewvisibility(animated: bool = true) {     if pickerheightconstraint.constant != 0 {         pickerheightvisible = pickerheightconstraint.constant         pickerheightconstraint.constant = 0     } else {         pickerheightconstraint.constant = pickerheightvisible     }     if animated {          uiview.animatewithduration(0.2, animations: {               () -> void in                self.view.layoutifneeded()          }, completion: nil)     } else {          view.layoutifneeded()     } } 

objective-c solution:

@property (nonatomic, strong) cgfloat pickerheightvisible; ... ... - (void)togglepickerviewvisibility:(bool)animated {     if(pickerheightconstraint.constant != 0) {         pickerheightvisible = pickerheightconstraint.constant;         pickerheightconstraint.constant = 0;     } else {         pickerheightconstraint.constant = pickerheightvisible;     }     if(animated) {          [uiview animatewithduration:0.2              animations:(void (^)(void))animations:^(void) {                   [self.view layoutifneeded];              }];     } else {           [self.view layoutifneeded];     } } 

disclaimer: have not tested nor compiled code above, give idea of how achieve it.

important: code above assumes give height constraint of picker view value greater 0 in storyboard/nib.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -