Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating Tab Bar page switching

Tags:

cocoa-touch

I'm quite confused with the whole animation stuff in iPhone SDK. I tried to study throught the SDK documentation, this website or tried googling it out without success. I'm unable to get my scenario work.

  • I have single XIB file, with tab bar and a 4 tabs.
  • In a special event i want to switch from one page to another "in code", so I call eg: [tabController selectedIndex: 0].
  • I need this transition to be animated. Is there a way?
  • If user switches tabs manually, no animated transitions are needed

Also I have one subquestion:

  • In one of the tabs I have a UITableView with set of items. When user clicks any of these items, another set of items are beign shown (sort of hierarchy browser)
  • I tried to animate this transition using -deleteRowsAtIndexPaths:withRowAnimation: and -insertRowsAtIndexPaths:withRowAnimation:, but without luck.
  • Desired transition is shifting the old items set to the left side and the new items from the right side.

This is first time of my iPhone development, when I got lost even with all the forums and documentation. :)

Thanks in advance to anyone trying to help me!


2 Answers

As for your first question: Yes you can. Try this link for some answer: transition on tab bar sample code.

In short words: you should add a delegate object to handle the tab bar switching by setting the tabBarController.delegate = self.
Yet, what this forum post won't tell you is that you need to "import" some framework to do it.
First - right-click on the framework folder on the left hand list in Xcode and add an existing framework named: "QuartzCore.framework".
Than - add these lines to your tab bar holder (on .h file):

#import <QuartzCore/CAAnimation.h>
#import <QuartzCore/CAMediaTimingFunction.h>

As for your second question, try to replace the datasource (array or what ever) or create login function on the cell to replace its content.

Enjoy!

like image 133
David Salzer Avatar answered Jan 29 '26 18:01

David Salzer


First Question: No, you can't animate tab switching. Please read Apple's Human Interface Guidelines on this. Tabs are meant to switch instantly. An animated transition would break the "tab" paradigm.

Second Question: When you tap on a row, the user does not expect other rows to disappear and new ones to appear. Instead, this sounds like a case for a UINavigationController. Please refer to Apple's sample code, specifically the UICatalog for sample code on how to implement this.

like image 22
August Avatar answered Jan 29 '26 20:01

August



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!