This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
linesConvergingAnimation.isReversed = true | |
// Finish animation in reverse | |
linesConvergingAnimation.startAnimation() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
linesConvergingAnimation = UIViewPropertyAnimator(duration: 0.2, curve: UIViewAnimationCurve.linear, animations: { | |
// Set the new constraints | |
self.firstLine.snp.remakeConstraints({ (make) in | |
make.height.equalTo(self.lineHeight) // constant | |
make.width.equalTo(self.containerView.snp.width) | |
make.centerX.equalTo(self.containerView.snp.centerX) | |
make.centerY.equalTo(self.containerView.snp.centerY) | |
}) | |
self.thirdLine.snp.remakeConstraints({ (make) in | |
make.height.equalTo(self.lineHeight) // constant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a completion block to the UIViewPropertyAnimator | |
linesConvergingAnimation.addCompletion({ (position) in | |
// since this is the reversed animation's completion block, the | |
// "final position" is the initial animation's target-start-position. | |
if position == .start { | |
self.linesAreX = false | |
// reset constraints back to normal | |
self.firstLine.snp.remakeConstraints({ (make) in | |
make.height.equalTo(self.lineHeight) | |
make.width.equalTo(self.containerView.snp.width) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// show a nav bar | |
// 1. change some constraints | |
navBarHeightConstraint.update(offset: 80) | |
// 2. animate | |
UIView.animate(withDuration: 0.10, delay: 0.0, options: .curveLinear, animations: { | |
self.view.layoutIfNeeded() // Apple docs: "layout the subviews immediately" | |
}, completion: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. change some constraints | |
navBarHeightConstraint.update(offset: 80) | |
// 2. animate | |
UIView.animate(withDuration: 0.10, delay: 0.0, options: .curveLinear, animations: { | |
self.navBar.layoutIfNeeded() | |
}, completion: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers = [1, 2, 3, 4, 5] | |
var evenNumbers = [Int]() | |
for i in 0..<numbers.count { | |
let number = numbers[i] | |
if number % 2 == 0 { | |
evenNumbers.append(number) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Returns an array containing, in order, the elements of the sequence | |
/// that satisfy the given predicate. | |
/// - Parameter shouldInclude: A closure that takes an element of the | |
/// sequence as its argument and returns a Boolean value indicating | |
/// whether the element should be included in the returned array. | |
/// - Returns: An array of the elements that `includeElement` allowed. | |
public func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> [Element] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers = [1, 2, 3, 4, 5].map { $0 * 2 } | |
print(numbers) // [2, 4, 6, 8, 10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arrayWithNoNils = [1, 2, 3, nil].flatMap { $0 } | |
print(arrayWithNoNils) // [1, 2, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arrayWithNoOptionals = ["1", "two", "3"].flatMap { Int($0) } | |
print(arrayWithNoOptionals) // [1, 3] |
OlderNewer