Pergunta

I have a UIScrollView sitting inside a popover. It is pinned to the edges of the popover using constraints, and it's full content is able to be displayed in the popover without scrolling (so the scroll view is not scrollable). When I tap a UITextField (located inside this scroll view), the keyboard slides up and the popover resizes. When the popover resizes, the UIScrollView becomes smaller and the content is now scrollable.

So my question is, how can I detect when my scroll view becomes scrollable?

P.S. I want to detect this so that I can set the delaysContentTouches property to YES when it is scrollable and to NO when the content is not scrollable.

Foi útil?

Solução

You can check to see if the contentSize is larger than the scrollView's bounds.

CGSize contentSize = scrollView.contentSize;
CGSize boundsSize = scrollView.bounds.size;
if (contentSize.width > boundsSize.width && contentSize.height > boundsSize.height) {
    // scrollable both vertically and horizontally
}
else if (contentSize.width > boundsSize.width) {
    // scrollable horizontally
}
else if (contentSize.height > boundsSize.height) {
    // scrollable vertically
}
else {
    // same size or smaller, not scrollable
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top