Swift4 Day88:Chain Animations連動動畫

Swift4 / iOS11 / 2018.04.07

Alice
Daily Swift
2 min readApr 6, 2018

--

最後成品,是做出這樣的動畫內容。

基礎設定

如果bodyLabel.text沒有設定的話,就只會有紅色的部分。

利用translatesAutoresizingMaskIntoConstraints與centerXAnchor讓文字在圖面中間,設定layout。

要讓addSubview在centerXAnchor前,不然會crash

文字換行

numberOfLines = 0,才能讓畫面呈現完整的文字。原本都是預設1。
搭配\n是在文字中下一行的方法。

widthAnchor設定與兩側的距離

利用widthAnchor,就可以做出距離兩側-100的大小

Extract Method

Xcode直接幫你做一個funciton(這好驚人第一次看到🙀)

太驚人了直接縮好>\\<

addGestureRecognizer

addGestureRecognizer中執行handleTapAnimations,所以在console中print出hello

Add animations

請看程式碼完整:按這

alpha = 0後會有fade的感覺,bodyLabel與titleLabel不同之處,在於bodyLabeldelay: 0.5。

出自:
Lets Build That App
的Swift: How to Chain Animations for Impressive Visual Effects,很棒的Youtube頻道🙆

--

--