Skip to content

Instantly share code, notes, and snippets.

@DavidPiper94
Last active March 4, 2021 05:18
Show Gist options
  • Select an option

  • Save DavidPiper94/40c3665216f0f777279f8231c265c672 to your computer and use it in GitHub Desktop.

Select an option

Save DavidPiper94/40c3665216f0f777279f8231c265c672 to your computer and use it in GitHub Desktop.
Example code for article about TagCloudView - Reacting to Resizing
// 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