Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

468
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda