简体   繁体   English

当SuperView UIScrollView滚动了UIView子类时,如何获得通知

[英]How can a UIView subclass get notified when it has been scrolled by its Superview UIScrollView

I am trying to subclass UIView and to get notified when its superviews got scrolled. 我试图子类化UIView并在滚动其超级视图时得到通知。 I tried with UIScrollView DidScroll delegate, But I want to create a standalone UIView to handle its movement on screen by itself. 我尝试使用UIScrollView DidScroll委托,但是我想创建一个独立的UIView来单独处理其在屏幕上的移动。 I tried by iterating its superviews and adding KVO for each superviews, but it might lead to performance issues. 我通过迭代其超级视图并为每个超级视图添加KVO进行了尝试,但这可能会导致性能问题。 Can you please suggest some better solution for this? 您能否为此提出一些更好的解决方案?

You can create a protocol for delegation, that you can set in parent UIViewController and implement function in sub view class. 您可以创建用于委托的协议,可以在父UIViewController中进行设置,并在子视图类中实现功能。 and call these protocol function from UIScrollView delegate method. 并从UIScrollView委托方法调用这些协议功能。

This should solve your problem 这应该可以解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM