import UIKit

class TimelineContainer: UIScrollView, ReusableView {

  var timeline: TimelineView!

  override func layoutSubviews() {
    timeline.frame = CGRect(x: 0, y: 0, width: frame.width, height: timeline.fullHeight)
  }

  func prepareForReuse() {
    timeline.prepareForReuse()
  }

  func scrollToFirstEvent() {
    if let yToScroll = timeline.firstEventYPosition {
      setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll), animated: true)
    }
  }
  
  func scrollTo(hour24: Float) {
    let percentToScroll = CGFloat(hour24 / 24)
    let yToScroll = contentSize.height * percentToScroll
    let padding: CGFloat = 8
    setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll - padding), animated: true)
  }
}

import UIKit

class TimelineContainer: UIScrollView, ReusableView {

  var timeline: TimelineView!

  override func layoutSubviews() {
    timeline.frame = CGRect(x: 0, y: 0, width: frame.width, height: timeline.fullHeight)
  }

  func prepareForReuse() {
    timeline.prepareForReuse()
  }

  func scrollToFirstEvent() {
    let yToScroll = timeline.firstEventYPosition ?? 0
    setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll), animated: true)
  }
  
  func scrollTo(hour24: Float) {
    let percentToScroll = CGFloat(hour24 / 24)
    let yToScroll = contentSize.height * percentToScroll
    let padding: CGFloat = 8
    setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll - padding), animated: true)
  }
}

--- 
+++ 
@@ -13,8 +13,9 @@
   }
 
   func scrollToFirstEvent() {
-    let yToScroll = timeline.firstEventYPosition ?? 0
-    setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll), animated: true)
+    if let yToScroll = timeline.firstEventYPosition {
+      setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll), animated: true)
+    }
   }
   
   func scrollTo(hour24: Float) {
Disable autoscroll if there are no events
