title: Using UIViewAnimationTransitionFlipFromRight to flip over a UIButton when pressed and show a new button on "the other side"
body: <p>EDITED For MOXY. </p>
  
  <p>I have an array of buttons with an image on top and array of buttons whose views are background colors. When i click on a button i want to retrieve that button index and use that index to also get the appropriate background color of the other view..and use that information to flip the button(with the image) and "turn it over" to reveal the background color.</p>
  
  <p>The make up of my screen is, ViewControllersView->TileView->(array of buttons).</p>
  
  <pre><code> -(void)viewDidAppear:(BOOL)animated{
   _viewContents = [model getRequestedView];  //this retrieves an array of UIButtons(24 
    //of them) whose frames and background colors have already been initialized to fit
     //within the TileView.
   _viewFrontImageContents =[model getRequestedViewFrontCardImagesWithFrame:_viewContents];
  
  for(int screenViewIndex = 0; screenViewIndex &lt; [_viewContents count]; screenViewIndex++){
      [TileView addSubview:[_viewFrontImageContents objectAtIndex:screenViewIndex]];
      [[_viewFrontImageContents objectAtIndex:screenViewIndex] addTarget:self action:@selector(frontOfCardPushed:) forControlEvents:UIControlEventTouchUpInside];
      //[TileView addSubview:[_viewContents objectAtIndex:screenViewIndex]];
      //[[_viewContents objectAtIndex:screenViewIndex] addTarget:self action:@selector(frontOfCardPushed:) forControlEvents:UIControlEventTouchUpInside];
  }
  
  }
  </code></pre>
  
  <p>//getRequestedViewFrontCardImagesWithFrame method</p>
  
  <pre><code>-(NSMutableArray *)getRequestedViewFrontCardImagesWithFrame:(NSArray *)views{
          NSMutableArray *cards = [[NSMutableArray alloc] init];
          UIImage *frontOfCardImage = [UIImage imageNamed:@"Back_of_Tile"];
          UIButton *frontOfCardView;
  
          for(int viewIndex = 0; viewIndex &lt; [views count]; viewIndex++){
              frontOfCardView = [[UIButton alloc] initWithFrame:[[views objectAtIndex:viewIndex] frame]];
              frontOfCardView.backgroundColor = [UIColor colorWithPatternImage:frontOfCardImage];
    //setting the tag of each frontCard to match the view index to keep them aligned.
              frontOfCardView.tag = viewIndex;
              [cards addObject:frontOfCardView];
  
              if(viewIndex == 0){
                NSLog(@"first frontcard frame %@, first _viewContentsFrame %@", [cards objectAtIndex:0], [views objectAtIndex:0]);
      }
          }
          return cards;
      }
  </code></pre>
  
  <p>Above I am adding UIButtons with an image on top to represent the "front of a playing card". The indices of said buttons matches exactly the indeces of the _viewContents array.I set up each button to match the frame(size and location) of the buttons that have been initialized already.</p>
  
  <pre><code>-(IBAction)frontOfCardPushed:(id)sender{
  int containerViewIndex = -1;
  UIButton *pressedButton = (UIButton *)sender;
  NSLog(@"Button Index: %i", pressedButton.tag);
  containerViewIndex = pressedButton.tag;
  UIView *container = [TileView viewWithTag:containerViewIndex];
  UIView *viewToShow = [_viewContents objectAtIndex:containerViewIndex];
  NSLog(@"container: %@, viewToShow: %@", container, viewToShow);
  //viewToShow.frame = container.frame;
  //NSLog(@"container: %@, viewToShow: %@", container, viewToShow);
  
  [UIView transitionWithView:container duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight
                  animations:^{
                      [sender removeFromSuperview];
                      [container addSubview:viewToShow];
                  }
                  completion:nil];
  </code></pre>
  
  <p>what I want to do is use a transition - namely 'UIViewAnimationTransitionFlipFromRight' to"flip the card" when pressed to reveal the contents of the associated _viewContents array. I also want to be able for the user to flip the card back over to reveal the image of the frontCardButton. This piece of code above just focuses on the first flip of the card to avoid a wall of code.</p>
  
  <p>I am seeing the appropriate background colors - but the animation itself is not working.</p>
  
  <p>What am i doing wrong and what do I need to add/remove to this piece of code to make it work?</p>
  
  <ul>
  <li>EDIT* 
  As noted below to Moxy, take a look at the output of whats in the getRequestedViewFrontCardImagesWithFrame method. Look at the output of the first card and then look at the output of the container view in the frontCardPushed: method after requesting the view with the appropriate tag - they do no match. I am printing out the button index so that you can see I am hitting the first TileView subview. The tag of the _viewContents view is a tag set the represents a color and has nothing to do with the TileView tag that I assign in the getRequestedViewFrontCardImagesWithFrame method. It is puzzling however that right after i assign a tag to the first button when i print it out, a tag isnt listed. </li>
  </ul>
  
  <p>OUTPUT:</p>
  
  <pre><code>//why doesnt the first frontcard frame list a tag? I had just assigned it one?
  </code></pre>
  
  <blockquote>
    <p>first frontcard frame UIButton: 0x1c53f020; frame = (6 5; 145 145);
    opaque = NO; layer = CALayer: 0x1c534ac0, first _viewContentsFrame
    UIButton: 0x1d045220; frame = (6 5; 145 145); opaque = NO; tag = 3;
    layer = CALayer: 0x1d04535</p>
    
    <p>Button Index: 0<br>
    container: UIView: 0x1c53a400; frame = (51 83; 922
    614); clipsToBounds = YES; autoresize = W+H; gestureRecognizers =
    NSArray: 0x1d05afe0>; layer = CALayer: 0x1c53a460, viewToShow:
    UIButton: 0x1d045220; frame = (6 5; 145 145); opaque = NO; tag = 3;
    layer = CALayer: 0x1d045350</p>
  </blockquote>