zoukankan      html  css  js  c++  java
  • ios按钮点击后翻转效果

    代码是网上找到的,不过找到的时候直接复制下来不能用,稍微整理下,为和我一样水平的菜鸟观摩一下下。

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

    C代码  收藏代码
    1. #include<QuartzCore/CoreAnimation.h>  

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

    C代码  收藏代码
    1. -(IBAction)buttonP:(id)sender{  
    2.     [self buttonAnimation:sender];  
    3. }  
    4.   
    5. - (CAAnimation *) animationRotate {  
    6.     CATransform3D rotationTransform  = CATransform3DMakeRotation( M_PI/2 , 0 , 1 , 0 );  
    7.     CABasicAnimation* animation;  
    8.     animation = [CABasicAnimation animationWithKeyPath:@"transform"];  
    9.     animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];  
    10.     animation.duration = 3;  
    11.     animation.autoreverses = YES;  
    12.     animation.cumulative = YES;  
    13.     animation.repeatCount = 1;  
    14.     animation.beginTime = 0.1;  
    15.     animation.delegate = self;  
    16.     return animation;  
    17. }  
    18.   
    19. - (void)buttonAnimation:(id) sender{  
    20.     UIButton *theButton = sender;  
    21.     CAAnimation *myAnimationRotate = [self animationRotate];  
    22.     CAAnimationGroup* m_pGroupAnimation;  
    23.     m_pGroupAnimation = [CAAnimationGroup animation];  
    24.     m_pGroupAnimation.delegate = self;  
    25.     m_pGroupAnimation.removedOnCompletion = NO;  
    26.     m_pGroupAnimation.duration = 10;  
    27.     m_pGroupAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];     
    28.     m_pGroupAnimation.repeatCount = 1;  
    29.     m_pGroupAnimation.fillMode = kCAFillModeForwards;  
    30.     m_pGroupAnimation.animations = [NSArray arrayWithObjects:myAnimationRotate, nil];  
    31.     [theButton.layer addAnimation:m_pGroupAnimation forKey:@"animationRotate"];  
    32. }  
    33.     
    34. - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{  
    35.     //todo  
    36. }  

    PS:

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

     

     

     

  • 相关阅读:
    eclipse快捷键
    go 中 var声明对比
    Post 中 Body 的 ContentType 用 Postman 举例
    MongoDB随笔(二) mongorestore恢复数据库
    MongoDB随笔(零) mongod配置 ...不断完善...会变得很长很长很长……
    MongoDB随笔(一)mac OSX下brew安装MongoDB
    mac OSX的 brew软件包管理器 相当于 centos下的yum
    2021-01-27 解决mac使用brew update更新无反应的问题(切换git地址)
    Ruby中实现module继承
    redmine问题集锦
  • 原文地址:https://www.cnblogs.com/lovewx/p/3824738.html
Copyright © 2011-2022 走看看