Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

454
Views
Swift Cocoa: Change NSScrollView frame size with animation

The result I want to achieve is this: Kext Wizard :

enter image description here

I can change the frame size but without any animation. Here is my simple code so far (didn't care too much about size but focus on animation):

@IBAction func disclosureButton(_ sender: Any) {
    if disclosureButton.state == .on {
        Swift.print("On")
        kextScroll.setFrameOrigin(kextScroll.frame.origin)
        kextScroll.setFrameSize(NSSize(width: 417, height: 316))
        //let rectBig = NSRect(origin: kextScroll.frame.origin, size: NSSize(width: 417, height: 316))
        //kextScroll.window?.setFrame(rectBig, display: true, animate: true)
    } else if disclosureButton.state == .off {
        Swift.print("Off")
        kextScroll.setFrameOrigin(kextScroll.frame.origin)
        kextScroll.setFrameSize(NSSize(width: 417, height: 200))
    }

}

Moreover if someone can give hint on how to show hidden menu as the frame size shrinks would be great. Thanks.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Ok problem solved by adding NSView to be set as boundary. Here is full code and Xcode picture

@IBAction func disclosureButton(_ sender: Any) {
    let dHeight = 70
    let smallOrigin = NSPoint(x: 20, y: 116)
    let bigOrigin = NSPoint(x: 20, y: 116-dHeight)
    let hideOrigin = NSPoint(x:0, y:25-dHeight)
    let showOrigin = NSPoint(x:0, y:25)
    if disclosureButton.state == .on {
        //hide
        NSAnimationContext.beginGrouping()
        NSAnimationContext.current.duration = 0.2
        kextScroll.animator().setFrameOrigin(bigOrigin)
        kextScroll.animator().setFrameSize(NSSize(width: 417, height: 249+dHeight))
        pathText.animator().setFrameOrigin(hideOrigin)
        reloadButton.animator().setFrameOrigin(NSPoint(x: 269, y:51-dHeight))
        unloadButton.animator().setFrameOrigin(NSPoint(x: 347, y:51-dHeight))
        exportButton.animator().setFrameOrigin(NSPoint(x: 269, y:-1-dHeight))
        revealButton.animator().setFrameOrigin(NSPoint(x: 347, y:-1-dHeight))
        kextLabel.animator().setFrameOrigin(NSPoint(x: 0, y:52-dHeight))
        NSAnimationContext.endGrouping()
    } else if disclosureButton.state == .off {
        //show
        NSAnimationContext.beginGrouping()
        NSAnimationContext.current.duration = 0.2
        kextScroll.animator().setFrameOrigin(smallOrigin)
        kextScroll.animator().setFrameSize(NSSize(width: 417, height: 249))
        pathText.animator().setFrameOrigin(showOrigin)
        reloadButton.animator().setFrameOrigin(NSPoint(x: 269, y:51))
        unloadButton.animator().setFrameOrigin(NSPoint(x: 347, y:51))
        exportButton.animator().setFrameOrigin(NSPoint(x: 269, y:-1))
        revealButton.animator().setFrameOrigin(NSPoint(x: 347, y:-1))
        kextLabel.animator().setFrameOrigin(NSPoint(x: 0, y:52))
        NSAnimationContext.endGrouping()
    }
}

So above code makes sure that all elements moves at same pace, just the question gif looks like. All hidden elements should be in a small NSView to show up properly.

Xcode So the element will be invisible if it is outside of the NSView. When the element moves into NSView range, it will not block other elements in the ViewController. Problem solved!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!