Detail the IOS layer transition animation

  • 2020-05-15 02:13:51
  • OfStack

A subclass of CAAnimation that animates transitions, providing layers with both on-screen and off-screen animations. iOS has 1 less animation effect than Mac OS X
UINavigationController USES CATransition to animate the controller's view to the screen
Property resolution:

type: animation transition type
subtype: animation transition direction
startProgress: animation starting point (percentage in overall animation)
endProgress: animation endpoint (percentage in overall animation)

Specific code:


/*  Transition effects 
 fade   // Cross desalination transition ( Does not support the transition direction ) kCATransitionFade
 push   // The new view pushes out the old view  kCATransitionPush
 moveIn  // The new view moves over the old view   kCATransitionMoveIn
 reveal  // Remove the old view , Display the new view below  kCATransitionReveal
 cube   // Cube roll effect 
 oglFlip // Flip up and down, left and right 
 suckEffect  // Contraction effect, such as 1 A piece of cloth was drawn away ( Does not support the transition direction )
 rippleEffect // Effect of water ( Does not support the transition direction )
 pageCurl   // Page up effect 
 pageUnCurl  // Page down effect 
 cameraIrisHollowOpen // Camera lens on effect ( Does not support the transition direction )
 cameraIrisHollowClose // Camera lens off effect ( Does not support the transition direction )
*/
  
/*  Direction of the transition 
 kCATransitionFromRight
 kCATransitionFromLeft
 kCATransitionFromBottom



// Transition animation -- it's about something view Layer to animate the transition 
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface ViewController ()
{
  UIView *_lastview;
  BOOL flag;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
  [super viewDidLoad];
  flag=true;
  UIView *view=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
  view.backgroundColor=[UIColor redColor];
  [self.view addSubview:view];
  [view release];
  _lastview=view;
  // Do any additional setup after loading the view, typically from a nib.
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  if(flag){
    _lastview.backgroundColor=[UIColor yellowColor];
    flag=false;
  
  }
  else{
    _lastview.backgroundColor=[UIColor redColor];
    flag=true;
  }
  
  // Transition animation -- just for one view Do the animation switch. 
  //1: If it's switching between controllers , Actually, window on view To switch 
  CATransition *transion=[CATransition animation];
  // Sets the type of transition animation 
  transion.type=@"pageCurl";
  // Set the direction of the transition animation 
  transion.subtype=@"fromLeft";
  
  // Add an animation to something view On the layer of 
  [self.view.layer addAnimation:transion forKey:nil];
  
}

The controller toggles the animation directly


 UIApplication *app=[UIApplication sharedApplication];
  AppDelegate *dd=app.delegate;
  
    MyViewController *my=[[MyViewController alloc] init];
  // Toggle the root controller and actually put the view controller's view in window On the switch. So in transition animation to play in window on 
  dd.window.rootViewController=my;
  CATransition *trans=[CATransition animation];
  
  trans.type=@"pageCurl";
  trans.subtype=@"fromTop";
  
  [dd.window.layer addAnimation:trans forKey:nil];
  
  [my release];

The above is the entire content of this article, I hope to help you with your study.


Related articles: