Top Banner
Twitter Profile Header Animation iOSすいすいもくもく会 @Livesense 2015.07.29 Tokyo @naoyashiga
23

Twitter Profile Header Animation by using Swift

Aug 17, 2015

Download

Technology

Naoya Sugimoto
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Twitter Profile Header Animation by using Swift

Twitter Profile Header Animation

iOSすいすいもくもく会@Livesense 2015.07.29 Tokyo @naoyashiga

Page 2: Twitter Profile Header Animation by using Swift

自己紹介

• @naoyashiga

• iOS Dev, Web Markup

• https://github.com/naoyashiga

• 趣味でiOSアプリ個人開発

Page 3: Twitter Profile Header Animation by using Swift

作ったアプリを 少しだけ紹介

Page 4: Twitter Profile Header Animation by using Swift

100万個のアワビ

Page 5: Twitter Profile Header Animation by using Swift

Thank you!!!!!!!!

Page 6: Twitter Profile Header Animation by using Swift

今日のLTは

Page 7: Twitter Profile Header Animation by using Swift

Twitter Profile Header Animation

Page 8: Twitter Profile Header Animation by using Swift

Twitterプロフィール画面を引っ張るとズームするやつ

Page 9: Twitter Profile Header Animation by using Swift

完璧に再現するのは難しいので何となく似たようなやつを

作ってみました

Page 10: Twitter Profile Header Animation by using Swift

Demo

Page 11: Twitter Profile Header Animation by using Swift

How to Blur

Page 12: Twitter Profile Header Animation by using Swift

Layer

Page 13: Twitter Profile Header Animation by using Swift

UIVisualEffect View• UIVisualEffect View

• Available iOS7~

• 透明度の変更は非推奨

• チラつく

• <UIVisualEffectView 0x7fd1d0440a20> is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.

Page 14: Twitter Profile Header Animation by using Swift

Blur Image Effect• Swift UIImage Effect

• Apple公式のUIImageEffectをSwiftで書いたやつ

• Apple非公式

• https://github.com/globchastyy/SwiftUIImageEffects

• GPUImage

• 試していないけど処理が速そう

• https://github.com/BradLarson/GPUImage

Page 15: Twitter Profile Header Animation by using Swift

Scroll Animation

Page 16: Twitter Profile Header Animation by using Swift

UIScrollViewDelegate• UITableViewDelegate

• UIScrollViewDelegate

• UITableViewDelegateに移譲済み

• scrollViewDidScroll

• スクロールしたら実行される

Page 17: Twitter Profile Header Animation by using Swift

Get ScrollY

func scrollViewDidScroll(scrollView: UIScrollView) { let scrollY = scrollView.contentOffset.y }

Page 18: Twitter Profile Header Animation by using Swift

scrollY < 0if scrollY < 0 { let pullDownOffsetY: CGFloat = 150 let scaleRatio = 1 - scrollY / pullDownOffsetY

headerImageView.transform = CGAffineTransformMakeScale(scaleRatio, scaleRatio)

blurredImageView.transform = CGAffineTransformMakeScale(scaleRatio, scaleRatio) let blurRatio = -scrollY / pullDownOffsetY blurredImageView.alpha = min(1.0, blurRatio) }

Page 19: Twitter Profile Header Animation by using Swift

scrollY > 0if scrollY > 0 { let headerHeightMovingSpeed = -scrollY / 2 let minHeight: CGFloat = view.frame.height * headerImageViewHeightConstraint.multiplier / 2

let constant: CGFloat = view.frame.height * headerImageViewHeightConstraint.multiplier - minHeight headerImageViewHeightConstraint.constant = max(-constant, headerHeightMovingSpeed)

view.layoutIfNeeded() }

Page 20: Twitter Profile Header Animation by using Swift

Set Imagevar headerBackgroundImage: UIImage? { didSet { let blurRadius: CGFloat = 20.0 headerImageView.image = headerBackgroundImage

blurredImageView.image = headerImageView.image?.applyBlurWithRadius(blurRadius, tintColor: nil, saturationDeltaFactor: 1.0, maskImage: nil)

} }

Page 21: Twitter Profile Header Animation by using Swift

Referrence• Implementing the Twitter iOS App UI - Think & Build

• http://www.thinkandbuild.it/implementing-the-twitter-ios-app-ui/

• How to create an interactive blur effect in iOS8 • Five

• http://five.agency/how-to-create-an-interactive-blur-effect-in-ios8/

Page 22: Twitter Profile Header Animation by using Swift

GitHub Repository

• https://github.com/naoyashiga/TwitterProfileHeaderAnimation

Page 23: Twitter Profile Header Animation by using Swift

Thank you!