(抄)页面转场动画

http://www.devqinwei.com/2015/10/27/页面转场动画/

1.模糊放大fade away 效果

代码:

+(void)changeRootViewControllerWithStyleBlur:(UIViewController *)viewController inMainWindow:(UIWindow *)mainWindow{

if (!mainWindow.rootViewController) {

mainWindow.rootViewController = viewController;

return;

}

UIView *snapShot = [mainWindow snapshotViewAfterScreenUpdates:YES];

[viewController.view addSubview:snapShot];

mainWindow.rootViewController = viewController;

[UIView animateWithDuration:0.5 animations:^{

snapShot.layer.opacity = 0;

snapShot.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5);

} completion:^(BOOL finished) {

[snapShot removeFromSuperview];

}];

}


2. 水平翻转效果

代码:

+ (void)changeRootViewControllerWithStyleFlip:(UIViewController*)viewController  inMainWindow:(UIWindow *)mainWindow{

if (!mainWindow.rootViewController) {

mainWindow.rootViewController = viewController;

return;

}

[UIView transitionWithView:mainWindow

duration:0.5f

options:UIViewAnimationOptionTransitionFlipFromLeft

animations:^{ mainWindow.rootViewController = viewController; }

completion:nil];

}

3. 仿twitter logo放大退隐动画

效果:

注:这个是写在navigationController上的,如果window的rootViewController是tabbarController,则需要做调整。(参考Kitten Yang的《A guide to iOS animation》)

代码:


@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// 设置navigationController 的 mask动画

self.navigationController.view.layer.mask = [CALayer layer];

self.navigationController.view.layer.mask.contents = (id)[UIImage imageNamed:@"star"].CGImage;

self.navigationController.view.layer.mask.position = self.view.center;

self.navigationController.view.layer.mask.bounds = CGRectMake(0.0f, 0.0f, 300.0f, 300.0f);

CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"bounds"];

keyFrameAnimation.delegate = self;

keyFrameAnimation.duration = 1.0f;

keyFrameAnimation.beginTime = CACurrentMediaTime() + 1.0f;

NSValue *initialBounds = [NSValue valueWithCGRect: self.navigationController.view.layer.mask.bounds];

NSValue *secondBounds = [NSValue valueWithCGRect:CGRectMake(0.0f, 0.0f, self.navigationController.view.layer.mask.bounds.size.width - 40.0f , self.navigationController.view.layer.mask.bounds.size.height - 40.0f)];

NSValue *finalBounds = [NSValue valueWithCGRect:CGRectMake(0.0f, 0.0f, 2000.0f, 2000.0f)];

keyFrameAnimation.values = @[initialBounds,secondBounds,finalBounds];

keyFrameAnimation.keyTimes = @[@0, @0.5, @1];

keyFrameAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut],[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut] ];

keyFrameAnimation.removedOnCompletion = NO;

keyFrameAnimation.fillMode = kCAFillModeForwards;

[self.navigationController.view.layer.mask addAnimation:keyFrameAnimation forKey:@"maskAnimation"];

// 设置一个在navigationController的layer和mask之间的白色隔层(注意,view如果添加subView,那么这个subView是在mask与view之间)

__block UIView *whiteView = [[UIView alloc] initWithFrame:self.navigationController.view.frame];

whiteView.backgroundColor = [UIColor whiteColor];

[self.navigationController.view addSubview:whiteView];

[self.navigationController.view bringSubviewToFront:whiteView];

// 设置navigationController的动画

[UIView animateWithDuration:0.25 delay:1.3 options:0 animations:^{

self.navigationController.view.transform = CGAffineTransformMakeScale(1.05, 1.05);

whiteView.alpha = 0.8f;

} completion:^(BOOL finished) {

[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

self.navigationController.view.transform = CGAffineTransformIdentity;

whiteView.alpha = 0.0f;

} completion:nil];

}];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • IOS动画+转场动画 #import "ViewController.h" #import "secondView...
    iOS小开发阅读 925评论 0 1
  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 1,144评论 1 6
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,141评论 5 13
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,572评论 6 30
  • 人生,不过就是一条从平原走进森林的路。平原上我们结伴而行,相濡以沫,而一旦进入了森林,草丛和荆棘挡路,情形就...
    Cheery1220阅读 165评论 0 0