2008-12-26 5 views

Répondre

16

Je pense que la seule chose que vous cherchez est:

de UIView
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache; 

et

UIViewAnimationTransitionFlipFromLeft, 
UIViewAnimationTransitionFlipFromRight, 

Ces transitions d'animation ne peuvent être utilisées que dans un bloc d'animation. La transition est définie sur la vue conteneur, puis l'ancienne vue est permutée pour la nouvelle vue, puis l'animation est validée.

Comme:

CGContextRef context = UIGraphicsGetCurrentContext(); 

[UIView beginAnimations:nil context:context]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:yourContainerView cache:YES]; 
[yourContainerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; 
[UIView commitAnimations]; 
+1

Trouvé une erreur. Devrait être "exchangeSubviewAtIndex" pas "exchangeSubviewsAtIndex". Merci. – bentford

+1

Le paramètre 'context' de' beginAnimtions: context: 'est vraiment juste pour garder certaines informations de contexte spécifiques à l'application. Il ne s'attend pas à un 'CGContextRef' là. –

0

Mettez votre UIImageView dans un UIView et utiliser ce code (à partir de l'échantillon de projet application utilitaire)

- (void)loadFlipsideViewController { 

    FlipsideViewController *viewController = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil]; 
    self.flipsideViewController = viewController; 
    [viewController release]; 

    // Set up the navigation bar 
    UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)]; 
    aNavigationBar.barStyle = UIBarStyleBlackOpaque; 
    self.flipsideNavigationBar = aNavigationBar; 
    [aNavigationBar release]; 

    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleView)]; 
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Test123"]; 
    navigationItem.rightBarButtonItem = buttonItem; 
    [flipsideNavigationBar pushNavigationItem:navigationItem animated:NO]; 
    [navigationItem release]; 
    [buttonItem release]; 
} 


- (IBAction)toggleView {  
    /* 
    This method is called when the info or Done button is pressed. 
    It flips the displayed view from the main view to the flipside view and vice-versa. 
    */ 
    if (flipsideViewController == nil) { 
     [self loadFlipsideViewController]; 
    } 

    UIView *mainView = mainViewController.view; 
    UIView *flipsideView = flipsideViewController.view; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES]; 

    if ([mainView superview] != nil) { 
     [flipsideViewController viewWillAppear:YES]; 
     [mainViewController viewWillDisappear:YES]; 
     [mainView removeFromSuperview]; 
     [infoButton removeFromSuperview]; 
     [self.view addSubview:flipsideView]; 
     [self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView]; 
     [mainViewController viewDidDisappear:YES]; 
     [flipsideViewController viewDidAppear:YES]; 

    } else { 
     [mainViewController viewWillAppear:YES]; 
     [flipsideViewController viewWillDisappear:YES]; 
     [flipsideView removeFromSuperview]; 
     [flipsideNavigationBar removeFromSuperview]; 
     [self.view addSubview:mainView]; 
     [self.view insertSubview:infoButton aboveSubview:mainViewController.view]; 
     [flipsideViewController viewDidDisappear:YES]; 
     [mainViewController viewDidAppear:YES]; 
    } 
    [UIView commitAnimations]; 
} 
0

MainView et flipToView sont des objets de imageViews et containerView est un objet de UIView.

Ci-dessous sont deux exemples de code pour friser les imageView et de retourner le ImageView de gauche à droite

 
- (void)curlAction:(id)sender 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.75]; 

    [UIView setAnimationTransition:([mainView superview] ?       UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown)forView:containerView cache:YES]; 
    if ([flipToView superview]) 
    { 
     [flipToView removeFromSuperview]; 
     [containerView addSubview:mainView]; 
    } 
    else 
    { 
     [mainView removeFromSuperview]; 
     [containerView addSubview:flipToView]; 
    } 

    [UIView commitAnimations]; 
} 

et pour amener l'image de gauche à est ici le code

 
- (void)flipAction:(id)sender 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.75]; 

    [UIView setAnimationTransition:([mainView superview] ? 
             UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) 
             forView:containerView cache:YES]; 
    if ([flipToView superview]) 
    { 
     [flipToView removeFromSuperview]; 
     [containerView addSubview:mainView]; 
    } 
    else 
    { 
     [mainView removeFromSuperview]; 
     [containerView addSubview:flipToView]; 
    } 

    [UIView commitAnimations]; 
} 

Remerciez & Cordialement

0

Une autre solution est disponible à mon repo mais cela n'implique pas encore d'animation! Il ne fait que manipuler les orientations de l'image pour fournir certains effets d'image à savoir basculer verticalement/horizontalement et faire pivoter de 90 degrés gauche/droite.