๐Ÿ“ฑ App Development Study/iOS๐ŸŽ

[Udemy iOS & Swift Bootcamp] Typing Animation(Timers, For loops)

ibelieveinme 2023. 6. 17. 15:11
728x90

์›ฐ์ปด ํ™”๋ฉด์˜ ๊ธ€์ž๋ฅผ ํƒ€์ดํ•‘ ์น˜๋Š” ๋“ฏํ•œ ์• ๋‹ˆ๋ฉ”์ด์…˜์œผ๋กœ ํ‘œํ˜„ํ•ด๋ณด์ž.


1. TextLabel ์Šคํฌ๋ฆฝํŠธ์— ์—ฐ๊ฒฐ

 

2. ๋ฐ˜๋ณต๋ฌธ์— ํƒ€์ด๋จธ ์ถ”๊ฐ€

import UIKit

class WelcomeViewController: UIViewController {

    @IBOutlet weak var titleLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        titleLabel.text = ""
        
        var charIndex = 0.0
        let titleText = "โšก๏ธFlashChat"
        for letter in titleText{
            print("-")
            print(0.1 * charIndex)
            print(letter)
            Timer.scheduledTimer(withTimeInterval: 0.1 * charIndex, repeats: false){ (timer) in
                self.titleLabel.text?.append(letter)
            }
            charIndex += 1
        }
    }
}

ํƒ€์ด๋จธ ๊ฐ„๊ฒฉ์— 0.1๋งŒ ๋„ฃ์–ด์ฃผ๋ฉด ๋ชจ๋“  ๊ธ€์ž๊ฐ€ 0.1์ดˆ๋งŒ์— ์ถœ๋ ฅ๋˜๋ฏ€๋กœ 0.1์— charIndex ๊ณฑํ•ด์ค˜์„œ 0.1, 0.2, ... ์ด๋Ÿฐ์‹์œผ๋กœ ๊ฐ’์„ ๋ถ€์—ฌํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๊ธฐํƒ€ ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ์ง€๋งŒ ๊ฐ„๋‹จํ•˜๊ฒŒ ์œ„์ฒ˜๋Ÿผ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

 

[์ฃผ์„ ์ถœ๋ ฅ ๊ฒฐ๊ณผ]

-

0.0

โšก๏ธ

-

0.1

F

-

0.2

l

-

0.30000000000000004

a

-

0.4

s

-

0.5

h

-

0.6000000000000001

C

-

0.7000000000000001

h

-

0.8

a

-

0.9

t

 

 

3. ๊ฒฐ๊ณผ๋ฌผ ํ™•์ธ

728x90