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
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
// 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
class LinkResponsiveTextView: UITextView { | |
override init(frame: CGRect, textContainer: NSTextContainer?) { | |
super.init(frame: frame, textContainer: textContainer) | |
self.delaysContentTouches = false | |
// required for tap to pass through on to superview & for links to work | |
self.isScrollEnabled = false | |
self.isEditable = false | |
self.isUserInteractionEnabled = true |
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
import SafariServices | |
var safariViewController: SFSafariViewController? | |
extension ViewController: SFSafariViewControllerDelegate { | |
func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) { | |
if !didLoadSuccessfully { | |
// check if online | |
print("couldn't open safari view") |
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 longPress = UILongPressGestureRecognizer(target: self, action: #selector(upgradeAlertViewOtherUpgradesLongPressHandler)) | |
longPress.minimumPressDuration = 0 | |
var longPressGRStartPoint: CGPoint? | |
var didCancelLongPressGR = false | |
func viewTouched(sender: UILongPressGestureRecognizer) { | |
let currentPoint = sender.location(in: self.view) | |
switch sender.state { | |
case .began: |
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
let evenNumbers = [1, 2, 3, 4, 5].filter { (number) -> Bool in | |
if number % 2 == 0 { | |
return true | |
} else { | |
return false | |
} | |
} |
OlderNewer