2

I need to listen to the position on the screen of a specific UIView. I need to know when this view goes in / out of the screen. This view can be embedded everywhere. So I can't listen to it's frame or bounds because in a scrollview or a cell, my view can go out of the screen, and this frame won't change. I also can't listen to the contentOffset of each scrollview in the view hierarchy because my specific view can be embedded in a simple container view that I can translate.

My only solution is to use a timer, and compute the position on the screen each x seconds, but I don't want to use a timer. Do you have a better idea? Is it possible to detect when a view is moving on the screen even if its frame doesn't change? Override drawRect?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • did you read about https://cocoacasts.com/key-value-observing-kvo-and-swift-3/ https://stackoverflow.com/questions/4874288/use-key-value-observing-to-get-a-kvo-callback-on-a-uiviews-frame – karthikeyan Jul 19 '17 at 08:30
  • Thank you for your response, but which property can I listen ? I can't listen the frame, because when my view is on a cell, the frame won't change... – Lucas Ortis Jul 19 '17 at 08:39
  • Timer this is not good solution but I think this is only thing way to do it. – Evgen Litvinenko Jul 19 '17 at 09:43

0 Answers0