-1

I want to create a slide-down animation, like in the image in the link. When I press on "Previous", I want it to slide down to the center of the screen. I am not really sure how to implement that. Any suggestion would be really handy.

http://imageshack.us/photo/my-images/718/slideto.png/

Cosmin
  • 2,840
  • 5
  • 32
  • 50

2 Answers2

1

This looks like a UITableView. You can place a custom cell with the button Previous, which will load the new data above and then call the scrollToRowAtIndexPath:atScrollPosition:animated: function to perform the animation.

Alexander
  • 8,117
  • 1
  • 35
  • 46
  • 1
    Header or footer views would be good solutions for placing such a button. – DarkDust Feb 22 '12 at 10:24
  • So basically I need to do two custom cells? One with for my data and one for my previous button? And can I change the background of the upper cells, that will be shown when I press Previous? – Cosmin Feb 22 '12 at 11:51
  • Yes, that was what I was suggesting. I've done a similar thing in one of my projects and it performs very well. – Alexander Feb 22 '12 at 11:52
  • But what about the background? Or maybe I can make three sections :-? One for my top cells, one for my previous buttons and one for my bottom cells. This way maybe I will be able to change the background color of the section above Previous. Because I need to make it look like in the picture. – Cosmin Feb 22 '12 at 11:55
  • Well, you can always chagne the `backgroundColor` of a `UITableViewCell` programatically. – Alexander Feb 22 '12 at 11:57
1

The whole thing is pretty likely a UIScrollView of some sort (UITableViews are scroll views as well). When the buttons is pressed, either use setContentOffset:animated: or scrollRectToVisible:animated: to do the scrolling. The "magic" is just in calculating the correct offset or rect. I'd suggest going with setContentOffset:animated:. It should work roughly like this:

CGPoint p;
p.x = 0;
// Get middle of the view to be centered.
p.y = CGRectGetMidY(myViewThatShouldBeCentered.frame);
// Need to offset it by half the scroll view frame, otherwise
// you'd just see the lower half of the view peeking out at the
// top of the scroll view.
p.y -= CGRectGetHeight(myScrollView.frame) / 2;
[myScrollView setContentOffset:p animated:YES];
DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • So you suggest I use two views, each one with its own TableView? – Cosmin Feb 22 '12 at 11:57
  • No, if you want to solve it with a table view (which might be the easiest solution) you just make one table view. Divide it into sections, like one section per day, and add the buttons as header or footer views (I guess in this case it's the later that makes more sense). When the button is pressed, either use `setContentOffset:animated:` or, like @Alexander suggested, use `scrollToRowAtIndexPath:atScrollPosition:animated:`. – DarkDust Feb 22 '12 at 12:00