sephiith
sephiith

Reputation: 1197

Move x and y coordinates of object on selection

Is it possible on selection of an object in this case the search bar, move it up to the top of the application view? How would I do that?

Currently the search bar is in the middle of the screen and when you press/click on it the table view appears under it.

Normally, when you press/click the search bar the navigation bar disappears and the search bar moves up. But because I have moved the search bar into the middle of the application and hid the navigation bar it no longer jumps to the top on selection.

Upvotes: 1

Views: 169

Answers (1)

Nicholas Smith
Nicholas Smith

Reputation: 11754

You could try UIView animateWithDurations.

So you'd have some code along the lines of:

[UIView animateWithDuration:0.3f animations:^{
       [yourSearchBar setFrame:CGRectMake(newX, newY, yourSearchBar.frame.size.width,
        yourSearchBar.frame.size.height)];
}
completion:^(BOOL finished) {}
];

That'll animate the move to a new X and Y coordinate so you can set where you want the bar to. Have that in a function that's triggered when the UISearchBar receives a touch event.

Upvotes: 1

Related Questions