Tuesday, September 25, 2012

iOS - Hide settings below tableView

Recently I posted a question on StackOverflow, on how you could possibly hide the settings menu below a tableview and let it be uncover from the top as it is done in the actual AppShopper App for iPhone.

I got some hints on how this could be done, but at the end I had to program the overall solution by myself. I answered my question already there, so you could probably just take the code from there, but as I find it quite interesting, and it could be used also in other projects I prefer to have it here in my blog.

I just put both views on the controller in the storyboard (the views get created in order, so the last in the list will be on top when the controller is shown) one over the other. Then you need to define a trigger for the uncover/cover function, which could be either a button, or a slide gesture or whatever. This trigger then needs to perform the following code

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
CGRect newFrame = self.newsTableView.frame;
newFrame.origin.y = newFrame.origin.y + self.subview.frame.size.height;
[self.subView1 setFrame:newFrame];
[UIView commitAnimations];

Maybe you need to adjust something else in your case, but more or less you should be done!

No comments: