Last active
March 4, 2021 05:18
-
-
Save DavidPiper94/40c3665216f0f777279f8231c265c672 to your computer and use it in GitHub Desktop.
Example code for article about TagCloudView - Reacting to Resizing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1 | |
| var timer: Timer? | |
| override func viewWillStartLiveResize() { | |
| super.viewWillStartLiveResize() | |
| startTimer() | |
| } | |
| // 2 | |
| func startTimer() { | |
| let repeatedTimer = Timer.scheduledTimer( | |
| withTimeInterval: 0.2, | |
| repeats: true | |
| ) { [weak self] _ in self?.buildRows() } | |
| timer = repeatedTimer | |
| RunLoop.main.add(repeatedTimer, forMode: .common) | |
| } | |
| // 3 | |
| override func viewDidEndLiveResize() { | |
| super.viewDidEndLiveResize() | |
| timer?.invalidate() | |
| buildRows() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment