activate 动画 animation

麻和雅
2023-12-01

View之间切换的动态效果设置:

    SettingsController *settings = [[SettingsController alloc]initWithNibName:@"SettingsView" bundle:nil];
    settings.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;  //水平翻转
    [self presentModalViewController:settings animated:YES];
    [settings release];



- (IBAction) activate:(UIView*)view

{

CGContextRef context = UIGraphicsGetCurrentContext();

[UIView beginAnimations:nilcontext:context];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:CONST_animation_time];

[view setCenter:UpPointOfView(view)];

CABasicAnimation *scalingAnimation = (CABasicAnimation *)[view.layeranimationForKey:@"scaling"];

if (!scalingAnimation)

{

scalingAnimation = [CABasicAnimationanimationWithKeyPath:@"transform"];

scalingAnimation.repeatCount=1

scalingAnimation.duration=CONST_animation_time;

scalingAnimation.autoreverses=NO;

scalingAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut];

scalingAnimation.fromValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.0,1.0, 1.0)];

scalingAnimation.toValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(CONST_enlarge_proportion,CONST_enlarge_proportion, 1.0)];

}

[view.layer addAnimation:scalingAnimationforKey:@"scaling"];

view.layer.transform =CATransform3DMakeScale(CONST_enlarge_proportion,CONST_enlarge_proportion, 1.0);

[UIView commitAnimations];

}


- (IBAction) deactivate:(UIView*)view

{

CGContextRef context = UIGraphicsGetCurrentContext();

[UIView beginAnimations:nilcontext:context];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:CONST_animation_time];

[view setCenter:DownPointOfView(view)];

CABasicAnimation *scalingAnimation = (CABasicAnimation *)[view.layeranimationForKey:@"descaling"];

if (!scalingAnimation)

{

scalingAnimation = [CABasicAnimationanimationWithKeyPath:@"transform"];

scalingAnimation.repeatCount=1

scalingAnimation.duration=CONST_animation_time;

scalingAnimation.autoreverses=NO;

scalingAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut];

scalingAnimation.fromValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(CONST_enlarge_proportion,CONST_enlarge_proportion, 1.0)];

scalingAnimation.toValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.0,1.0, 1.0)];

}

[view.layer addAnimation:scalingAnimationforKey:@"descaling"];

view.layer.transform =CATransform3DMakeScale(1.0,1.0, 1.0);

[UIView commitAnimations];

}

 类似资料: