您的位置:首页 > 移动开发 > IOS开发

ios 视图切换动画效果

2011-12-07 16:31 459 查看

ios 视图切换动画效果

ios view与view间切换的动画效果这篇文章中简单介绍了一种动画效果,下面我详细介绍一下ios中页面间跳转系统自带的动画效果。

动画效果可以参考:http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState

下面先介绍第一组动画效果:

















实现的代码是:

//view1中的动画

- (IBAction)doUIViewAnimation:(id)sender{

[UIView beginAnimations:@"animationID" context:nil];

[UIView setAnimationDuration:10.5f];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationRepeatAutoreverses:NO];

UIButton *theButton = (UIButton *)sender;

switch (theButton.tag) {

case 0:

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//oglFlip, fromLeft

break;

case 1:

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];//oglFlip, fromRight

break;

case 2:

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

break;

case 3:

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];

break;

default:

break;

}

[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];

[UIView commitAnimations];

}

主要是从不同的角度产生动画。

第二组动画效果:











实现的代码:

- (IBAction)doPublicCATransition:(id)sender{

CATransition *animation = [CATransition animation];

//animation.delegate = self;

animation.duration = 10.5f;

animation.timingFunction = UIViewAnimationCurveEaseInOut;

animation.fillMode = kCAFillModeForwards;

//animation.removedOnCompletion = NO;

UIButton *theButton = (UIButton *)sender;

/*

kCATransitionFade;

kCATransitionMoveIn;

kCATransitionPush;

kCATransitionReveal;

*/

/*

kCATransitionFromRight;

kCATransitionFromLeft;

kCATransitionFromTop;

kCATransitionFromBottom;

*/

switch (theButton.tag) {

case 0:

animation.type = kCATransitionPush;

animation.subtype = kCATransitionFromTop;

break;

case 1:

animation.type = kCATransitionMoveIn;

animation.subtype = kCATransitionFromTop;

break;

case 2:

animation.type = kCATransitionReveal;

animation.subtype = kCATransitionFromTop;

break;

case 3:

animation.type = kCATransitionFade;

animation.subtype = kCATransitionFromTop;

break;

default:

break;

}

[self.view.layer addAnimation:animation forKey:@"animation"];

}

下面看一下第三种效果:




















代码实现:

- (IBAction)doPrivateCATransition:(id)sender{

//http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState

/*

Don’t be surprised if Apple rejects your app for including those effects,

and especially don’t be surprised if your app starts behaving strangely after an OS update.

*/

CATransition *animation = [CATransition animation];

animation.delegate = self;

animation.duration = 10.5f * slider.value;

animation.timingFunction = UIViewAnimationCurveEaseInOut;

animation.fillMode = kCAFillModeForwards;

animation.endProgress = slider.value;

animation.removedOnCompletion = NO;

UIButton *theButton = (UIButton *)sender;

switch (theButton.tag) {

case 0:

animation.type = @"cube";//—

break;

case 1:

animation.type = @"suckEffect";//103

break;

case 2:

animation.type = @"oglFlip";//When subType is "fromLeft" or "fromRight", it’s the official one.

break;

case 3:

animation.type = @"rippleEffect";//110

break;

case 4:

animation.type = @"pageCurl";//101

break;

case 5:

animation.type = @"pageUnCurl";//102

break;

case 6:

animation.type = @"cameraIrisHollowOpen ";//107

break;

case 7:

animation.type = @"cameraIrisHollowClose ";//106

break;

default:

break;

}

[self.view.layer addAnimation:animation forKey:@"animation"];

self.lastAnimation = animation;

if(slider.value == 1)

[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//Just remove, not release or dealloc

else{

for (int i = 0; i < [self.view.subviews count]; i++) {

[[self.view.subviews objectAtIndex:i] setUserInteractionEnabled:NO];

}

isHalfAnimation = YES;

}

}

以上是ios中常用的动画效果,还有一些是利用2d自己写的动画效果,关于自定义动画以后在研究。

源代码:http://easymorse-iphone.googlecode.com/svn/trunk/UIViewDemo/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: