How to access subzones in nested UIScrollViews

I was having trouble getting a UIScrollView with multiple UIImageView subzones for proper scaling, so I tried using a UIScrollView with several subordinate UIScrollViews inside it and a UIImageView inside each one. Thus, one UIScrollView can scroll, and the other can only increase.

My question is: how can I access subviews view. I know that usually I can access subviews using [scrollView viewWithTag:tagInt];, for example, but I cannot access subviews subview using [[scrollView viewWithTag:tagInt] viewWithTag:tagInt2];, because viewWithTag returns only one UIView and not all of its subviews.

I could always give each view a unique tag and access them that way, but this seems to be not the most elegant solution.

What is the best way to access subView and then go to subview subView (i.e. access my UIScrollView used for scaling, which is a subview of my main view, and then access the subView UIImageView)?

+3
source share
3 answers

If you don’t feel comfortable subclassing right now, you’ll have to assign tags to UIScrollViews that contain images. You would have to do what Bobk offered with a bit more work.

for (UIView *subview in [myScrollView subviews])
{
   //check if the current subview is one of the UIScrollViews
   if (subview.tag > 100)
        //do something with the UIScrollView
}
+3
source

- UIScrollView, UIImageView. , UIImageView - :

MyScrollView *myScrollView = (MyScrollView *)[scrollView viewWithTag:tagInt];
UIImageView *imageView = myScrollView.imageView;

, !

0

You can get an array of routines of any UIView using the subviews property.

for(UIView *subview in [myScrollView subviews]) {
     // do anything with your subview here. 
}
0
source

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


All Articles