activate 动画 animation

本文介绍了一种在iOS应用中实现视图切换时的动态效果的方法。通过使用UIKit和Core Animation,可以创建平滑的过渡动画,如水平翻转效果,并实现视图放大和缩小的动画。这些技术能够提升用户体验,使应用程序界面更加生动有趣。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

<wbr><wbr><wbr>SettingsController *settings = [[SettingsController alloc]initWithNibName:@"SettingsView" bundle:nil];<br><wbr><wbr><wbr>settings.modalTransitionStyle = UIModalTransitionStyleFl<wbr>ipHorizontal;<wbr>//水平翻转<br><wbr><wbr><wbr>[self presentModalViewControll<wbr>er:settings animated:YES];<br><wbr><wbr><wbr>[settings release];</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>



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

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值