1

I have created a new project with one button and one hidden NSView (I called this annimationView). The idea is when user pressed the button than the hidden view should fade in and out. But nothing happens on the first time. If I press the button again it works perfectly.

This is my code. Does have anybody an idea what i'm doing wrong?

 override func viewDidLoad() {
    super.viewDidLoad()
    animationView.wantsLayer = true
    animationView.layer?.backgroundColor = NSColor(red: 223/255.0, green: 240/255.0, blue:  216/255.0, alpha: 1.0).CGColor
    // Do any additional setup after loading the view.
}

@IBAction func click(sender: AnyObject) {

    NSAnimationContext.runAnimationGroup({ (context) -> Void in
        self.animationView.hidden = false
        context.duration = 2.0
        self.animationView.animator().alphaValue = 1

        }, completionHandler: { () -> Void in

            self.animationView.alphaValue = 0
            self.animationView.hidden = true         
    })
}
septicorn
  • 142
  • 1
  • 12
alex.b
  • 184
  • 1
  • 2
  • 15
  • 1
    You don't need to hide/unhide view using the hidden property as you want to just show and hide view with animation. You should ensure alphaValue is 0 before you ever click. – Shripada Sep 02 '15 at 12:19
  • @Shripada Thanks it worked for me – alex.b Sep 02 '15 at 15:48

0 Answers0