UIView.animate not animating on one function
Fixed it by animating the bottom constraint of the view instead of its frame.
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseInOut, animations: {
self.viewBottomConstraint.constant = -500
self.view.layoutIfNeeded()
}) { (_) in
self.view.removeFromSuperview()
}
Got a hint out of this: https://stackoverflow.com/a/52378252/9629494
UIView.animateWithDuration not animating
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 = CGRect(x: 20, y: 20, width: 30, height: 30)
led.layer.cornerRadius = 15
UIView.animate(withDuration: 3.0, animations:{
led.alpha = 0.5
led.frame = CGRect(x: 25, y: 25, width: 20, height: 20)
led.layer.cornerRadius = 10
}, completion:{(value: Bool) in
print("completion \(value)")
})
}
// ...
}
UIView.animate not work correctly in swift
Try triggering notification on main thread
DispatchQueue.main.async {
NotificationCenter.default.addObserver(self, selector: #selector(self.showResult), name: NSNotification.Name(rawValue: "SHOWRESULT"), object: nil)
}
Reason:
Regular notification centers deliver notifications on the thread in
which the notification was posted. Distributed notification centers
deliver notifications on the main thread. At times, you may require
notifications to be delivered on a particular thread that is
determined by you instead of the notification center. For example, if
an object running in a background thread is listening for
notifications from the user interface, such as a window closing, you
would like to receive the notifications in the background thread
instead of the main thread. In these cases, you must capture the
notifications as they are delivered on the default thread and redirect
them to the appropriate thread.
UiView.animateWithDuration Not Animating Swift
Before the animateWithDuration, set the XPosition to -200 and YPosition to -200.
Like Daniel Suggested, you need to also change the alpha from something other than 1.0 in order to see it "fade in".
Are you using autolayout? If you are, you may want to animate the constraints instead of the frame.
Finally, are you sure you've wired up the search bar properly?
Edit: PS, I would keep the duration to something like 3.0 or 5.0. 10.0 will take forever and may make you think that it isn't doing anything because of how long it takes. Make it 3.0 or 5.0 (max) just for testing and then decrease to where you want it.
UIView.animatewithDuration not animating when activated by button
For future travelers stuck at the same predicament: You have to control your views using autolayout if they're subview of views using autolayout as well. Otherwise you get the weird results I was getting.
Here is an excellent guide on how to do that.
Related Topics
Xcode 6.1 Swift Extensions - Sourcekit Service Crash
Reduce Float Precision Using Regexp in Swift
How to Implement Applescript Support in a Swift Macos App
Convert Input Data to Integer in Swift
The "Funk" Sound When Hitting Escape Key in App
How to Parse Url # Fragments with Query Items in Swift
In Swift, Dynamic Height for UItextview in UIcollectionview
How to Stop Firestore Pagination When Searched Data Are Loaded in Tableview
Convert Ble Current Time to Date
Communicate Data Between Watchos & Today Extension Widget
How to Horizontally Center Content of Horizontal Scrollview
How to Get The Nearest Int Floored from a Sqrt of an Int
Swift: Strange Behavior About Unwrapping
Anchor Constraints Not Honored in Xcode 10/iOS 12
Swift: Forward Keystrokes to a Different Process
How to Get Unsaferawpointer on The Swift Object
(Key: Anyobject, Value: Anyobject)' Does Not Have a Member Named 'subscript'
Swiftui Custom View Repeat Forever Animation Show as Unexpected