2010-07-31 99 views
0

首先這裏是我的代碼:FlipFromRight的UIView動畫

[_helperView addSubview:_navigationController.view]; 
[_helperView addSubview:itemView]; 

[UIView beginAnimations:@"pageFlipAnimation" context:nil]; 
[UIView setAnimationDuration:1.0]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_helperView cache:NO]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(pageFlipAnimationDidStop)]; 
[itemView removeFromSuperview]; 
[UIView commitAnimations]; 

我這個,沒有什麼是動畫的問題。如果我之前添加_navigationController.view和itemView(我的意思不是在這個方法中),一切都可以,但是當我在動畫之前添加它時什麼也不做。我也嘗試再次調用動畫didStopSelector中的動畫,並且在那裏工作。 你能幫我解答爲什麼它不想在這種情況下工作?任何建議如何解決它?

回答

1

您應該給UI提供實現itemView的添加的機會。要做到這一點,添加一行addSubview:itemView後:

[self performSelector(removeAnim:) withObject:itemView afterDelay:0.01]; 

和動畫塊移動到一個功能

-(void)removeAnim:(UIVieW*)itemView 

這應該可以解決這個問題。

0

使用QuartzCore.framework有了這些動畫。

-(void)viewSlideInFromRightToLeft:(UIView *)views 
{ 
    CATransition *transition = nil; 
    transition = [CATransition animation]; 
    transition.duration = 0.5;//kAnimationDuration 
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type = kCATransitionPush; 
    transition.subtype =kCATransitionFromRight; 
    transition.delegate = self; 
    [views.layer addAnimation:transition forKey:nil]; 
} 

-(void)viewSlideInFromLeftToRight:(UIView *)views 
{ 
    CATransition *transition = nil; 
    transition = [CATransition animation]; 
    transition.duration = 0.5;//kAnimationDuration 
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type = kCATransitionPush; 
    transition.subtype =kCATransitionFromLeft; 
    transition.delegate = self; 
    [views.layer addAnimation:transition forKey:nil]; 
} 

-(void)viewSlideInFromTopToBottom:(UIView *)views 
{ 
    CATransition *transition = nil; 
    transition = [CATransition animation]; 
    transition.duration = 0.5;//kAnimationDuration 
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type = kCATransitionPush; 
    transition.subtype =kCATransitionFromBottom ; 
    transition.delegate = self; 
    [views.layer addAnimation:transition forKey:nil]; 
} 

-(void)viewSlideInFromBottomToTop:(UIView *)views 
{ 
    CATransition *transition = nil; 
    transition = [CATransition animation]; 
    transition.duration = 0.5;//kAnimationDuration 
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type = kCATransitionPush; 
    transition.subtype =kCATransitionFromTop ; 
    transition.delegate = self; 
    [views.layer addAnimation:transition forKey:nil]; 
} 

對於將animationType您可以使用以下選項: - >kCATransitionMoveInkCATransitionPushkCATransitionRevealkCATransitionFade

對於AnimationSubType您可以使用以下選項: - >kCATransitionFromLeftkCATransitionFromRightkCATransitionFromTopkCATransitionFromBottom