UIButton frame coordinates aren't updated after View is moved

I have a scrollView with a bunch of buttons + textfields, and when data is entered in one element, the scrollview scrolls to the next element. I'm accessing each elements location via the frame component

However, the user can upload an image, which intentionally moves all those elements down the page. This completely breaks the scrolling to the next element functionality, and it is only scrolling to where the elements used to be. Meaning, the frame component for each UIButton, UITextField isn't getting updated.

When I move all those elements down, how do I get their coordinates updated? Should I not be using frame?

For more detail, the fields actually sit on a View, which then sits on top of the UIScrollView. When I add the image, I move the field View by shifting the frame down the screen. I'm not moving each button/field itself.

- (void)scrollViewToNextElement:(CGRect)frame {
[self.scrollView scrollRectToVisible:CGRectMake(frame.origin.x,frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height) animated:YES];
}

Trigger action:

-(void)button1TextEntered{
// Now go to the next button
[self scrollViewToNextElement:button2.frame];

}

Answers


Take the scrollview frame and reduce the frame origin.y by some value. When you enter value and press enter scrollview origin.y value will move up. This way you can fix it.


Need Your Help

Where eclipse stores information about jars associated with a Library

eclipse ant jar

I've written an ant task that extracts the classpath of a project form eclipse's .classpath file - so I don't need to maintain the project's dependencies both in eclipse and in my ant file.