尝试将动画部分放在控制器类中而不是在子类按钮类中.

//in customButton.h file

#import

@interface customButton : UIButton

- (id)initWithFrameOfCustomButton:(CGRect)frame;

- (void)animate;//this method u need to add and call it from the controller

@end

//in the subclassed UIButtin class

//in customButton.m file

#import "customButton.h"

#import

@implementation customButton

- (id)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

// Initialization code

}

return self;

}

- (id)initWithFrameOfCustomButton:(CGRect)frame

{

self = [super initWithFrame:frame];

if(self)

{

//hear only set the frame only not incude animation part

//this is the custom initiliser that initilises the custom button with the given frame and also make it to round

self.frame = frame;

self.backgroundColor = [UIColor greenColor];

self.layer.cornerRadius = frame.size.width/2;

self.layer.masksToBounds = YES;

}

return self;

}

//add the animation part

- (void)animate //this method is called within the this class

{

[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

self.layer.affineTransform = CGAffineTransformMakeScale(0.0f,0.0f);

//edit: comment below lines becz u already made it to round

// self.layer.cornerRadius = 0.0f;

// self.layer.masksToBounds = YES;

// self.clipsToBounds = YES;

// CATransform3D t = CATransform3DIdentity;

// t = CATransform3DMakeScale(0,1.0f);

// cButton.layer.transform = t;

} completion:^(BOOL finished) {

[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

self.layer.affineTransform = CGAffineTransformMakeScale(1.0f,1.0f);

// edit comment below lines

// self.layer.cornerRadius = self.frame.size.width/2;

// self.layer.masksToBounds = YES;

// self.clipsToBounds = YES;

// CATransform3D t = CATransform3DIdentity;

// t = CATransform3DMakeScale(1,1,1.0f);

// cButton.layer.transform = t;

} completion:nil];

}];

}

//implement touch handling methods to call animation

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

[self animate];

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

{

[self animate];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

// [self animate];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

// [self animate];

}

在控制器类中包括如下的动画部分

//in the view controller that u are using this custom button

#import "FirstViewController.h"

#import "CustomCell.h"

#import "customButton.h"

#import

@interface FirstViewController ()

@end

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

// Custom initialization

}

return self;

}

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

customButton *cButton = [[customButton alloc]initWithFrameOfCustomButton:CGRectMake(20,30,100,100)]; //hear i am initilising the custom button

cButton.tag = 100;//assigning tag to access during the animation

[self.view addSubview:cButton];

// [self makeAnimation];//i am animation rite after it loads the all views u can place this method call where ever u want

//edit: i am commenting the this line so animations of the button in this class won't call

}

//edit below method is added

- (void)viewDidAppear:(BOOL)animated

{

customButton *cButton = (customButton *)[self.view viewWithTag:100];

//edit->comment this line so that u never call the animation from view controller

// [cButton animate];//animating the button the code in the subclassed method is called

}

- (void)makeAnimation

{

customButton *cButton = (customButton *)[self.view viewWithTag:100];//get the custom button by using the tag

[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

cButton.layer.affineTransform = CGAffineTransformMakeScale(0.0f,0.0f);

// cButton.layer.cornerRadius = 0.0f;

// cButton.layer.masksToBounds = YES;

// cButton.clipsToBounds = YES;

// CATransform3D t = CATransform3DIdentity;

// t = CATransform3DMakeScale(0,1.0f);

// cButton.layer.transform = t;

} completion:^(BOOL finished) {

[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

cButton.layer.affineTransform = CGAffineTransformMakeScale(1.0f,1.0f);

// cButton.layer.cornerRadius = cButton.frame.size.width/2;

// cButton.layer.masksToBounds = YES;

// cButton.clipsToBounds = YES;

// CATransform3D t = CATransform3DIdentity;

// t = CATransform3DMakeScale(1,1.0f);

// cButton.layer.transform = t;

} completion:nil];

}];

}

注意UIButton继承自:UIControl – > UIView – > UIResponder – > NSObject的

如果你感到困惑,请查看文档

如果你想使用UIControlers,即响应者,那么你需要实现这些方法

你可以得到你想要的活动,

在您的子类UIButton类中,通过注释触摸处理方法来实现它

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event

{

return YES;

}

- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event

{

}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event

{

return YES;

}

ios开发 方形到圆的动画_ios – cornerRadius上的CGAffineTransformMakeScale动画圆形UIButton...相关推荐

  1. ios开发 方形到圆的动画_画个圆动画,的两种实现。iOS 动画由很浅,入浅,当然是 Swift...

    方法一,使用 CAShapeLayer 和 UIBezierPath 加上 CABasicAnimation 有一个动画属性 strokeEnd 就算完 方法二,复杂一些.频繁调用 CALayer 的 ...

  2. ios开发 方形到圆的动画_iOS利用UIBezierPath + CAAnimation实现路径动画效果

    前言 上次给大家介绍了iOS利用UIBezierPath + CAAnimation实现路径动画效果的相关内容,今天实现一个根据心跳路径实现一个路径动画,让某一视图沿着路径进行运动.. 效果图如下: ...

  3. ios开发 方形到圆的动画_3Blue1Brown 动画制作教程(1)--制作第一个自己的动画

    制作第一个自己的动画 前一篇详细介绍了 3Blue1Brown 的动画引擎在 Windows 10 64 位系统上,基于 Anaconda的配置方法,并且详细描述了在配置 3Blue1Brown 提供 ...

  4. ios开发 方形到圆的动画_使用UIBezierPath画个圆动画

    UIBezierPath主要用来绘制矢量图形,它是基于Core Graphics对CGPathRef数据类型和path绘图属性的一个封装,所以是需要图形上下文的(CGContextRef),所以一般U ...

  5. iOS开发系列–打造自己的“美图秀秀”(上)

    iOS开发系列–打造自己的"美图秀秀"(上) 概述 在iOS中可以很容易的开发出绚丽的界面效果,一方面得益于成功系统的设计,另一方面得益于它强大的开发框架.今天我们将围绕iOS中两 ...

  6. IOS开发基础之使用AFNetworking框架实现文件上传get和post请求

    IOS开发基础之使用AFNetworking框架实现文件上传get和post请求 AFNetworking框架 请自行从github官网clone.命令为 git clone xxx.xxx是项目的地 ...

  7. ios开发中计算代码运算时间_iOS日历、日期、时间的计算

    时间和日历的计算在iOS开发中经常看到,经常看到大家在百度,开源中国等搜索这些答案.今天写个简单的时间和日历有关的计算. 获取一个月的总天数 1.获取当月的天数 - (NSInteger)getNum ...

  8. iOS开发之结合asp.net webservice实现文件上传下载

    iOS开发中会经常用到文件上传下载的功能,这篇文件将介绍一下使用asp.net webservice实现文件上传下载. 首先,让我们看下文件下载. 这里我们下载cnblogs上的一个zip文件.使用N ...

  9. iOS开发中,通过URL地址获取网络上的图片

    在iOS开发中,我们有时会通过图片的URL地址来获取网上的图片,下面是一个方法实现: /** 通过URL地址从网上获取图片 */ -(UIImage *) getImageFromURL:(NSStr ...

最新文章

  1. 在WCF中实现双工通信(转载)
  2. 祝师傅新婚快乐 :-)
  3. 使用IDEA 创建SpringBoot项目
  4. 紧跟潮流的背景设计,赶紧尝试用新的背景改变旧的设计。
  5. 从零开始的Python学习Episode 19——面向对象(2)
  6. jdk的官方下载地址
  7. 简单工具之 ---- IP地址快速修改脚本
  8. 2020年全球锂电池电芯产值将超过3400亿元
  9. 用C#实现汉字转化为拼音
  10. Android获取CPU使用率的几种方式
  11. python 下载 M3U8 视频
  12. 利用Canvas 实现前端图片涂抹效果
  13. Monitor Linux —使用zabbix服务器的跨平台固件
  14. 《人月神话》-第16章-没有银弹
  15. Day 5 E. Arranging The Sheep
  16. 常见C++开源网站项目
  17. Bitstream Vera Sans Mono 编程字体安装
  18. 安装和配置NFS服务器
  19. 必读论文 | 卷积神经网络百篇经典论文推荐
  20. 练手/翻译软件/有道翻译API/XML解析/正则/Java

热门文章

  1. c语言存款利息的计算有1000,【c语言】存款利息的计算
  2. 小程序微商城 解决方案
  3. javaEE mysql在线音乐试听网
  4. python优质网站合集
  5. MyBatis-Plus入门和使用实践
  6. 在 centOS 上设置目录文件权限
  7. 数据库中外键绑定的属性必须是被参照表的主键吗?
  8. SkyWalking--OAL--使用/教程/示例
  9. poj3614Sunscreen 贪心
  10. 如何判断电路板上贴片电容的参数