87075

UIView.animateWithDuration not animating

The UIView.animateWithDuration call in my ViewController viewDidLoad function does not animate. The completion block gets called immediately. The println output shows 'completion true'. Is the viewDidLoad function the wrong place to put my startup animation? Any hints are greatly appreciated.

class ViewController: UIViewController { @IBOutlet var beatIndicator:UIView? override func viewDidLoad() { super.viewDidLoad() if let led = beatIndicator? { led.alpha = 1.0 led.frame = CGRectMake(20, 20, 30, 30) led.layer.cornerRadius = 15 UIView.animateWithDuration(3.0, animations:{ led.alpha = 0.5 led.frame = CGRectMake(25, 25, 20, 20) led.layer.cornerRadius = 10 }, completion:{(value: Bool) in println("completion \(value)") }) } // ... } }

Answer1:

Have you tried putting it in ViewDidAppear?

override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) if let led = beatIndicator? { led.alpha = 1.0 led.frame = CGRectMake(20, 20, 30, 30) led.layer.cornerRadius = 15 UIView.animateWithDuration(3.0, animations:{ led.alpha = 0.5 led.frame = CGRectMake(25, 25, 20, 20) led.layer.cornerRadius = 10 }, completion:{(value: Bool) in println("completion \(value)") }) } // ... }

Answer2:

viewDidLoad() is not the ideal place where you should animate views. I tried your code in the viewDidAppear() method and it works.

Recommend

  • UINavigationController alternatives
  • UITableView without still works!
  • Printing input from TextField to a Label in Xcode with Swift
  • Sharing Redis settings across routes
  • Reinitialise existing jQuery flexslider with new options
  • I have a modal that opens a second modal and cannot close the first modal if open then close the sec
  • Where to put clearQueue in jQuery code
  • div fade-in when window is scrolled a certain distance from the top
  • MeeGo Handset Emulator not starting on Windows 7
  • How Get arguments value using inline assembly in C without Glibc?
  • Excel's Macro-Recorder usage
  • How to get Eclipse Oxygen to run on Java 9
  • How to use carriage return with multiple line?
  • Custom Tabgroup Appcelerator
  • Meteor: Do Something On Email Verification Confirmation
  • Java: can you cast Class into a specific interface?
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Projection media query: browser support and workarounds?
  • Different response to non-authenticated users and AJAX calls
  • AES padding and writing the ciphertext to a disk file
  • Controls, properties, events and timers running in design time
  • Updating server-side rendering client-side
  • How to extract text from Word files using C#?
  • Where to put my custom functions in Wordpress?
  • Updated Ionic CLI but shows previous version (Windows)
  • Weird JavaScript statement, what does it mean?
  • RestKit - RKRequestDelegate does not exist
  • WPF Applying a trigger on binding failure
  • Java static initializers and reflection
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • need help with bizarre java.net.HttpURLConnection behavior
  • unknown Exception android
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Observable and ngFor in Angular 2
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • How to load view controller without button in storyboard?