View Flip Animation Question

Discussion in 'iOS Programming' started by jchildress, Aug 13, 2008.

  1. jchildress macrumors member

    Joined:
    Jul 9, 2008
    #1
    I'm using the "UIViewAnimationTransitionFlipFromRight" command to flip a view from right to left, and then again from left to right to go back. As the view flips, the distinctive empty black background behind the flipping view animation, in my opinion, is ugly.

    I think I can change the background color, but I thought it would be really cool if I can have an image back there instead. So I tried to add a UIImageView to the window in the MainWindow.XIB, but that did nothing. Does anybody have any ideas on how to do this?
     
  2. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #2
    I've never seen this done before. Increase the speed of your animation if you don't like the colour behind the flip to reduce its exposure time. Either that or change the animation to UIViewAnimationTransitionCurlUp for a cool fade effect, both animations are visually impressive from a users point of view.
     
  3. Sbrocket macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #3
    jchildress - The point of a UIViewAnimationTransitionFlipFromRight is to flip the view to some other view. The right way to use it is like this:

    Code:
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.75];     /* Sub. duration here */
    		
    UIView *superview;
    if ((superview = [frontSideView superview])) {
    	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:superview cache:YES];
    	[frontSideView removeFromSuperview];
    	[superview addSubview:backSideView];
    } else if ((superview = [backSideView superview])) {
    	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:superview cache:YES];
    	[backSideView removeFromSuperview];
    	[superview addSubview:frontSideView];
    }
    
    [UIView commitAnimations];
    
    Of course you need to make sure that the views are elsewhere retained when you do this because -removeFromSuperview sends a -release message to its target.

    UIViewAnimationTransitionCurlUp is only a fade on the iPhone Simulator - on the device, its the animation its actually supposed to be, which is the curl up (and away) animation.
     
  4. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #4
    cool! never got to test my app on a device so luckily i decided to stick with the flipping transition! :eek:
     
  5. TripleJ macrumors regular

    Joined:
    Jul 30, 2008
    #5
    On a related note, does anybody know if it is possible to flip a view inside a tab bar controller? I can't quite get my head around it
     
  6. Buschmaster macrumors 65816

    Buschmaster

    Joined:
    Feb 12, 2006
    Location:
    Minnesota
    #6
    It's just the same.

    What seems to be the problem you're having?
     
  7. TripleJ macrumors regular

    Joined:
    Jul 30, 2008
    #7
    I've got a tab bar with 5 tabs, each with their own view in. I want to be able to touch that view and then flip it over to reveal another view. The thing is I'm not sure how to target each specific tab in the tab bar using the code. It's probably quite simple and I've a feeling I'd need to use something like tabBarController.selectedIndex = 0; but I can't get it working.
     
  8. jchildress thread starter macrumors member

    Joined:
    Jul 9, 2008
    #8
    TripleJ, that's what I'm doing and it works for me. I'm at work and currently away from my code. but I can post it later if you need me to. What I'm doing is pretty hacky due to my inexperiance with Obj-C. So maybe other people can critique my code and tell me how to improve it. but it works for me.

    One thing I'd like to know... Can I modify a single index value in an NSArray. for example. I want to get the array of currentViewControllers from my tabBarController and then swap out a specific controller with a new one. In other languages I'm used to, I would try something like this:

    myArray[0] = newViewController;

    Is there a "setObjectAtIndex" method for an NSArray? So something like:

    [myArray setObjectAtIndex:newViewController];

    Thanks,
    Jason
     
  9. TripleJ macrumors regular

    Joined:
    Jul 30, 2008
    #9
    If you could, Jason, that would be very much appreciated :) Thank you in advance!
     
  10. Sbrocket macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #10
    There is for NSMutableArray.
    -[NSMutableArray replaceObjectAtIndex:withObject:]
     
  11. michaelbox macrumors newbie

    Joined:
    Aug 27, 2009
    #11
    Use UIColor's colorWithPatternImage

    self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:mad:"img.png"]];
     

Share This Page