Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS swift expandable view [closed]

I would like to expand an view when I switch a switch to on, and to collapse when I switch the switch to off. At the same time all the other elements I have in my design have to move down or up.

Here is how the layout looks like when the switches are OFF

And here is how the layout looks like when the switches are ON:

I hope you understand what I am trying to do.

And the question... How do I do that???

like image 408
user3861818 Avatar asked Jul 29 '14 11:07

user3861818


People also ask

How Get Mobile IP address in Swift?

To get IPAddress for wifi , wired, and cellular - swift 5func getIPAddress() -> String { var address: String? var ifaddr: UnsafeMutablePointer<ifaddrs>? = nil if getifaddrs(&ifaddr) == 0 { var ptr = ifaddr while ptr != nil { defer { ptr = ptr?.


1 Answers

It's much easier to do with AutoLayout and inside InterfaceBuilder (with a xib or storyboard), so foremost familiarize yourself with them if needed.

  1. Wrap a container UIView around the UISwitches and make sure to set it to Clip Subviews.
  2. Add a constraint for the container view's height and set it to 0.
  3. Drag that constraint into your class declaration to generate an IBOutlet property.
  4. Drag a new outlet from your UISwitch 'Value Changed' event to the class to generate an IBAction method.
  5. Make sure to implement that method so that when the value changes, based on the change you toggle-animate the height constraint (the IBOutlet)

    self.firstHeightConstraint.constant = on ? 200.0 : 0.0
    self.view.setNeedsUpdateConstraints()
    UIView.animateWithDuration( ... 
        options:.BeginFromCurrentState, 
        animations: { self.view.layoutIfNeeded() } ...
    )
    
like image 64
hlfcoding Avatar answered Oct 15 '22 12:10

hlfcoding