Question

In my iOS application i have a scrollview in which there are many imageviews and textviews. I have to move all this views down to a fixed value, but i don't want to move them to left, right or resize them. I just want to move them down, on an event. The problem is that i can't know which are the values of these UIView.

This is my code:

for(UIView* subview in [myScrollView subviews])
{
    subview.frame = CGRectMake(0, 0, screenWidth, screenHeight);
} 

i'd like to do this:

for(UIView* subview in [myScrollView subviews])
{
    subview.frame = CGRectMake(previousValue+100, previousValue, previousValue, previousValue);
} 

I hope I explained myself

Was it helpful?

Solution

If you just want to move them down, why don't you just set scrollView's contentInset?

scrollView.contentInset = UIEdgeInsetsMake(100, previousValue, previousValue, previousValue);

this will make all your subViews down.

OTHER TIPS

try something like this:

UIView *lastView;
for(UIView* subview in [myScrollView subviews])
{
    CGrect lastFrame;
    if (!lastView) {
        lastFrame = CGRectMake(0,0,100,100); // your initial frame
    } else {
        lastFrame = lastView.frame;
    }
    lastFrame.origin.x += 100;
    subview.frame = lastFrame;
    lastView = subview;
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top