How should UIScrollView user perceptions about their boundaries be considered for contentSize?

I am looking for more tips on the right design to view.

I have a UIScrollView that contains one or more custom views that I created. My problem is who reports in scrollview what is contentSize? I have the following:

UIView  
+-UIScrollView  
  +-CustomView 1 with dynamic height depending on data
  +-CustomView 2 with dynamic Height depending on data

The UIViewController creates new instances of custom data views, and then adds them as subitems to the UIScrollView. The problem I am facing is how to set the value of scrollview contentSize? Right now, I am not doing this, and the contents of scrollview are cropped without being able to scroll.

  • Should the user call view [parent setContentSize:] in his drawRect :?
  • If a UIViewController requests a custom view after creation to get its borders, then calls setContentSize?
  • Should I subclass UIScrollView to override addSubView to request each candlestick height?
  • Is there anything else I am missing?

I hope I explained it correctly. I am new to this and still understand things.

+3
source share
1 answer

ContentSize in the scroll view should be the size of the frame union of all your custom views. Whenever the size of a custom view is changed, or one is added or removed, the view manager must calculate the new contentSize and apply it.

drawRect: .
.
UIScrollView, .

+1

Source: https://habr.com/ru/post/1746790/


All Articles