(抄)頁(yè)面轉(zhuǎn)場(chǎng)動(dòng)畫

http://www.devqinwei.com/2015/10/27/頁(yè)面轉(zhuǎn)場(chǎng)動(dòng)畫/

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. 水平翻轉(zhuǎn)效果

代碼:

+ (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放大退隱動(dòng)畫

效果:

注:這個(gè)是寫在navigationController上的,如果window的rootViewController是tabbarController,則需要做調(diào)整。(參考Kitten Yang的《A guide to iOS animation》)

代碼:


@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// 設(shè)置navigationController 的 mask動(dòng)畫

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"];

// 設(shè)置一個(gè)在navigationController的layer和mask之間的白色隔層(注意,view如果添加subView,那么這個(gè)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];

// 設(shè)置navigationController的動(dòng)畫

[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];

}];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • IOS動(dòng)畫+轉(zhuǎn)場(chǎng)動(dòng)畫 #import "ViewController.h" #import "secondView...
    iOS小開(kāi)發(fā)閱讀 952評(píng)論 0 1
  • 1、禁止手機(jī)睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa閱讀 1,208評(píng)論 1 6
  • 在iOS中隨處都可以看到絢麗的動(dòng)畫效果,實(shí)現(xiàn)這些動(dòng)畫的過(guò)程并不復(fù)雜,今天將帶大家一窺iOS動(dòng)畫全貌。在這里你可以看...
    F麥子閱讀 5,270評(píng)論 5 13
  • 在iOS中隨處都可以看到絢麗的動(dòng)畫效果,實(shí)現(xiàn)這些動(dòng)畫的過(guò)程并不復(fù)雜,今天將帶大家一窺ios動(dòng)畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,693評(píng)論 6 30
  • 人生,不過(guò)就是一條從平原走進(jìn)森林的路。平原上我們結(jié)伴而行,相濡以沫,而一旦進(jìn)入了森林,草叢和荊棘擋路,情形就...
    Cheery1220閱讀 183評(píng)論 0 0

友情鏈接更多精彩內(nèi)容