Animate chevron rotation

This commit is contained in:
Maurice Parker 2019-09-27 05:42:16 -05:00
parent 25fa5e0167
commit 3464fbfc7f
7 changed files with 49 additions and 13 deletions

View File

@ -48,12 +48,12 @@ struct AppAssets {
return UIImage(systemName: "circle")! return UIImage(systemName: "circle")!
}() }()
static var chevronDownImage: UIImage = { static var chevronSmallImage: UIImage = {
return UIImage(systemName: "chevron.down")! return UIImage(named: "chevronSmall")!
}() }()
static var chevronRightImage: UIImage = { static var chevronBaseImage: UIImage = {
return UIImage(systemName: "chevron.right")! return UIImage(named: "chevronBase")!
}() }()
static var copyImage: UIImage = { static var copyImage: UIImage = {

View File

@ -152,15 +152,18 @@ private extension MasterFeedTableViewCell {
func addDisclosureView() { func addDisclosureView() {
disclosureButton = NonIntrinsicButton(type: .roundedRect) disclosureButton = NonIntrinsicButton(type: .roundedRect)
disclosureButton!.addTarget(self, action: #selector(buttonPressed(_:)), for: UIControl.Event.touchUpInside) disclosureButton!.addTarget(self, action: #selector(buttonPressed(_:)), for: UIControl.Event.touchUpInside)
disclosureButton?.setImage(AppAssets.chevronBaseImage, for: .normal)
updateDisclosureImage() updateDisclosureImage()
addSubviewAtInit(disclosureButton!) addSubviewAtInit(disclosureButton!)
} }
func updateDisclosureImage() { func updateDisclosureImage() {
if disclosureExpanded { UIView.animate(withDuration: 0.3) {
disclosureButton?.setImage(AppAssets.chevronDownImage, for: .normal) if self.disclosureExpanded {
} else { self.disclosureButton?.imageView?.transform = CGAffineTransform(rotationAngle: 1.570796)
disclosureButton?.setImage(AppAssets.chevronRightImage, for: .normal) } else {
self.disclosureButton?.imageView?.transform = CGAffineTransform(rotationAngle: 0)
}
} }
} }

View File

@ -66,6 +66,8 @@ class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView {
private let unreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero) private let unreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero)
private var disclosureView: UIImageView = { private var disclosureView: UIImageView = {
let iView = NonIntrinsicImageView() let iView = NonIntrinsicImageView()
iView.tintColor = UIColor.tertiaryLabel
iView.image = AppAssets.chevronSmallImage
iView.contentMode = .center iView.contentMode = .center
return iView return iView
}() }()
@ -131,11 +133,12 @@ private extension MasterFeedTableViewSectionHeader {
} }
func updateDisclosureImage() { func updateDisclosureImage() {
disclosureView.tintColor = UIColor.tertiaryLabel UIView.animate(withDuration: 0.3) {
if disclosureExpanded { if self.disclosureExpanded {
disclosureView.image = AppAssets.chevronDownImage self.disclosureView.transform = CGAffineTransform(rotationAngle: 1.570796)
} else { } else {
disclosureView.image = AppAssets.chevronRightImage self.disclosureView.transform = CGAffineTransform(rotationAngle: 0)
}
} }
} }

View File

@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "chevron-base.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

View File

@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "chevron-small.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}