iOS - CATransition (過渡動畫)

簡介

CAAnimation 的子類,主要用於做過渡動畫、轉場動畫等。

屬性

屬性 解釋
type 表示過渡效果,公開 API 有四種
kCATransitionFade 漸變
kCATransitionMoveIn 進入覆蓋
kCATransitionPush 推出
kCATransitionReveal 揭露離開
還有一些私有API的動畫類型,效果很炫酷,不過不推薦使用。比如"cube", “suckEffect”, “rippleEffect”, “pageCurl”, “pageUnCurl”, “oglFlip”, “cameraIrisHollowOpen”, “cameraIrisHollowClose”, “spewEffect”,“genieEffect”,“unGenieEffect”,“twist”,“tubey”,“swirl”,“charminUltra”, “zoomyIn”, “zoomyOut”, "oglApplicationSuspend"等等。
注:kCATransitionFade 不支持Subtype
subtype 表示過渡方向,有四種
kCATransitionFromRight 從右側進入
kCATransitionFromLeft 從左側進入
kCATransitionFromTop 從頂部進入
kCATransitionFromBottom 從底部進入
startProgress 動畫起點(在整體動畫的百分比)
endProgress 動畫終點(在整體動畫的百分比)

實踐

轉場動畫

    self.animationView = [[UIView alloc]init];
    self.animationView.frame = CGRectMake(200, kHeight/2-50, 50, 50);
    self.animationView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:self.animationView];
    
    CATransition *anima = [CATransition animation];
    anima.type = kCATransitionPush;
    anima.subtype = kCATransitionFromRight; 
    anima.duration = 1.0f;
    [self.animationView.layer addAnimation:anima forKey:@"transitionAnimation"];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章