I'm trying to do a card flip animation...but nothing happens.
this is what I do 1. create a container view, to hold the two views to animate from. 2. Create the first view. 3. add it to the container. 4. create the second view 3. start the animation block, beginAnimations 4. call setAnimationTransition put in the view container 5. add the second view to the view container 6. commit the animation,
my code
// create container view
CGRect viewRect = CGRectMake(10, 10, 100, 100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
// create 2 viues to flip betwe开发者_如何学Pythonen for animation
UIImage *i= [ UIImage imageNamed : @"card1.jpg"];
UIImageView *topCard=[ [UIImageView alloc] initWithImage: i ];
topCard.frame= CGRectMake(0,0,100,100);
[myView addSubview:topCard];
[self.view addSubview:myView];
i= [ UIImage imageNamed : @"card2.jpg"];
UIImageView *butCard=[ [UIImageView alloc] initWithImage: i ];
butCard.frame= CGRectMake(0,0,100,100);
// set up the animation
[UIView beginAnimations:@"Flip Top Card" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:0];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut ];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[myView addSubview:butCard];
// start the animation
[UIView commitAnimations];
-Ted
If this is iOS 4.0 or later you can do:
[UIView transitionWithView:myView
duration:0.3f
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^(void) {
self.topCardIsShown = !self.topCardIsShown;
self.topCard.hidden = !self.topCardIsShown;
self.butCard.hidden = self.topCardIsShown;
}
completion:^(BOOL finished) {
// nothing
}];
This assumes that you have added both card views to the myView and have added a @property(nonatomic, assign) BOOL topCardIsShown;
to your class.
精彩评论