Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

455
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda