-3

I created a simple tab bar app with 2 view controllers - FirstViewController and SecondViewController. I added the following to the First, why doesn't this animate?

- (void)viewWillAppear:(BOOL)animated
{
    [UIView transitionWithView:self.view
                      duration: 2.0
                      options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionTransitionCrossDissolve
                      animations:^(void){
                          [super viewWillAppear:YES ];
                      } completion:^(BOOL finished){}];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jon
  • 1,608
  • 7
  • 25
  • 38

1 Answers1

1

It cannot animate because (1) viewWillAppear is too soon — the view isn't even in the interface yet, so what's to animate? and (2) it's not up to you to animate this view into place — if you wanted to do that, you'd have to write a custom transition animation, and that's not how to do it.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • It's utterly unclear from your code what you're hoping to do, and your question doesn't explain your intentions. But whatever they are, that code is wrong in every sense. – matt Oct 30 '15 at 04:22
  • Why doesn't this work http://stackoverflow.com/questions/5161730/iphone-how-to-switch-tabs-with-an-animation – Jon Oct 30 '15 at 20:18
  • Is that what you are trying to do? Change tabs in a tab bar controller with animation? – matt Oct 30 '15 at 21:35
  • Yes.. when you click on tab. The tab animates into view. That's it – Jon Oct 31 '15 at 01:19
  • 1
    It's all in my book! Here's the example I develop there: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch06p292customAnimation1/ch19p620customAnimation1/AppDelegate.swift As I said, you have to write a custom transition animation. This shows you how. – matt Oct 31 '15 at 02:02
  • thanks.. how does this transfer to iOS - this is swift? correct – Jon Oct 31 '15 at 14:25
  • I've answered the question. I've given you working code in a project that you can download and run. I've written you a book that explains that code to you! I really think my job here is done. – matt Oct 31 '15 at 17:01
  • Yes.. thanks.. it's in swift and runs great. Looking to do it Xcode – Jon Oct 31 '15 at 18:07
  • 1
    You are doing it in Xcode already. Do you mean you need the same thing in Objective-C? https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/iOS7bookExamples/bk2ch06p292customAnimation1/ch19p620customAnimation1/AppDelegate.m – matt Oct 31 '15 at 18:12