3d翻转 ios_ios按钮点击后翻转效果

上图先,图上是一个按钮,点击后旋转,代码是网上找到的,不过找到的时候直接复制下来不能用,稍微整理下,为和我一样水平的菜鸟观摩一下下。

(1)引入“QuartzCore.framework”库,头部引用。

#include

(2)直接上代码,你懂的。

-(IBAction)buttonP:(id)sender{

[self buttonAnimation:sender];

}

- (CAAnimation *) animationRotate {

CATransform3D rotationTransform = CATransform3DMakeRotation( M_PI/2 , 0 , 1 , 0 );

CABasicAnimation* animation;

animation = [CABasicAnimation animationWithKeyPath:@"transform"];

animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];

animation.duration = 3;

animation.autoreverses = YES;

animation.cumulative = YES;

animation.repeatCount = 1;

animation.beginTime = 0.1;

animation.delegate = self;

return animation;

}

- (void)buttonAnimation:(id) sender{

UIButton *theButton = sender;

CAAnimation *myAnimationRotate = [self animationRotate];

CAAnimationGroup* m_pGroupAnimation;

m_pGroupAnimation = [CAAnimationGroup animation];

m_pGroupAnimation.delegate = self;

m_pGroupAnimation.removedOnCompletion = NO;

m_pGroupAnimation.duration = 10;

m_pGroupAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

m_pGroupAnimation.repeatCount = 1;

m_pGroupAnimation.fillMode = kCAFillModeForwards;

m_pGroupAnimation.animations = [NSArray arrayWithObjects:myAnimationRotate, nil];

[theButton.layer addAnimation:m_pGroupAnimation forKey:@"animationRotate"];

}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{

//todo

}

PS:

CATransform3DMakeRotation(M_PI/2,0,1,0);第一个参数是旋转的角度,有一点需要著名,就是对象回按照你设定的角度的最短距离去旋转,后面三个参数分别是xyz(-1~1之间的值)代表的一个向量值。顺时针或者逆时针旋转尚未搞定具体是什么参数来控制的,有知道的朋友提醒下,谢谢!

大小: 46.2 KB

大小: 38.4 KB

大小: 30.1 KB

分享到:

2012-03-21 23:17

浏览 13834

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值