ios view與view間切換的動畫效果

(1)項目中添加QuartzCore.framework組件


(2)在預編譯文件中添加 

    #import<QuartzCore/QuartzCore.h>, 這樣所有需要的文件都可以直接使用


(3)

- (IBAction) clickToSecond:(id) sender {    

    //加載將要切換的視圖

   UIViewControllerSecond * secondView = [[UIViewControllerSecond  alloc] initWithNibName:@"UIViewControllerSecond"bundle:nil];

   //傳參數

    secondView.view.frame =self.view.frame;  

    //設置爲當前視圖的同級視圖

    [self.viewaddSubview:secondView.view];

        

   //定義動畫類型

   CATransition *animation = [CATransition  animation]; 

    animation.delegate =self

    animation.duration =1.25f

    animation.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]

    animation.fillMode =kCAFillModeForwards

    animation.type =kCATransitionFade

    animation.subtype =kCATransitionFromRight

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

}





- (IBAction) clickReturnHome: (id) sender {

    

   CATransition *animation = [CATransition  animation]; 

    animation.delegate =self

    animation.duration =0.50f

    animation.timingFunction[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]

    animation.fillMode =kCAFillModeBoth

    animation.type =kCATransitionFade

    animation.subtype =kCATransitionFromRight;

    

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

    [self.viewremoveFromSuperview]; 

}



注意: 這2個切換視圖之間的關係是父子視圖關係。


切換顯示還可以參考蘋果實例: ViewTransitions, 其中切換視圖是平級關係。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章