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")!
}()
static var chevronDownImage: UIImage = {
return UIImage(systemName: "chevron.down")!
static var chevronSmallImage: UIImage = {
return UIImage(named: "chevronSmall")!
}()
static var chevronRightImage: UIImage = {
return UIImage(systemName: "chevron.right")!
static var chevronBaseImage: UIImage = {
return UIImage(named: "chevronBase")!
}()
static var copyImage: UIImage = {

View File

@ -152,15 +152,18 @@ private extension MasterFeedTableViewCell {
func addDisclosureView() {
disclosureButton = NonIntrinsicButton(type: .roundedRect)
disclosureButton!.addTarget(self, action: #selector(buttonPressed(_:)), for: UIControl.Event.touchUpInside)
disclosureButton?.setImage(AppAssets.chevronBaseImage, for: .normal)
updateDisclosureImage()
addSubviewAtInit(disclosureButton!)
}
func updateDisclosureImage() {
if disclosureExpanded {
disclosureButton?.setImage(AppAssets.chevronDownImage, for: .normal)
} else {
disclosureButton?.setImage(AppAssets.chevronRightImage, for: .normal)
UIView.animate(withDuration: 0.3) {
if self.disclosureExpanded {
self.disclosureButton?.imageView?.transform = CGAffineTransform(rotationAngle: 1.570796)
} 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 var disclosureView: UIImageView = {
let iView = NonIntrinsicImageView()
iView.tintColor = UIColor.tertiaryLabel
iView.image = AppAssets.chevronSmallImage
iView.contentMode = .center
return iView
}()
@ -131,11 +133,12 @@ private extension MasterFeedTableViewSectionHeader {
}
func updateDisclosureImage() {
disclosureView.tintColor = UIColor.tertiaryLabel
if disclosureExpanded {
disclosureView.image = AppAssets.chevronDownImage
} else {
disclosureView.image = AppAssets.chevronRightImage
UIView.animate(withDuration: 0.3) {
if self.disclosureExpanded {
self.disclosureView.transform = CGAffineTransform(rotationAngle: 1.570796)
} else {
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"
}
}