编写带有点击特效的UIButton

效果:

源码:

//
// ViewController.m
// Button
//
// Created by XianMingYou on 15/1/18.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UIView *showView;
@property (nonatomic, strong) UILabel *showLabel;
@property (nonatomic, strong) UILabel *staticLabel; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor]; self.showView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
self.showView.transform = CGAffineTransformMakeRotation( * M_PI / 180.0);
self.showView.userInteractionEnabled = NO;
self.showView.backgroundColor = [UIColor redColor]; self.staticLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
self.staticLabel.text = @"YouXianMing";
self.staticLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:.f];
self.staticLabel.textAlignment = NSTextAlignmentCenter;
self.staticLabel.textColor = [UIColor redColor]; self.showLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
self.showLabel.text = @"YouXianMing";
self.showLabel.alpha = .f;
self.showLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:.f];
self.showLabel.textAlignment = NSTextAlignmentCenter;
self.showLabel.textColor = [UIColor blackColor]; // 完整显示按住按钮后的动画效果
_button = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
_button.backgroundColor = [UIColor clearColor];
_button.layer.borderWidth = .f;
_button.layer.borderColor = [UIColor redColor].CGColor;
_button.layer.masksToBounds = YES;
_button.center = self.view.center;
[self.view addSubview:_button]; self.showView.center = CGPointMake(_button.frame.size.width / .f, _button.frame.size.height / .f);
[_button addSubview:self.showView]; self.staticLabel.center = CGPointMake(_button.frame.size.width / .f, _button.frame.size.height / .f);
[_button addSubview:self.staticLabel]; self.showLabel.center = CGPointMake(_button.frame.size.width / .f, _button.frame.size.height / .f);
[_button addSubview:self.showLabel]; // 按住按钮后没有松手的动画
[_button addTarget:self
action:@selector(scaleToSmall)
forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter]; // 按住按钮松手后的动画
[_button addTarget:self
action:@selector(scaleAnimation)
forControlEvents:UIControlEventTouchUpInside]; // 按住按钮后拖拽出去的动画
[_button addTarget:self
action:@selector(scaleToDefault)
forControlEvents:UIControlEventTouchDragExit];
} - (void)scaleToSmall {
[UIView animateWithDuration:0.5f animations:^{
self.showView.bounds = CGRectMake(, , , );
self.showView.backgroundColor = [UIColor redColor];
self.showLabel.alpha = .f;
} completion:^(BOOL finished) {
NSLog(@"%d", finished);
}];
} - (void)scaleAnimation {
// 获取到当前的状态
self.showView.bounds = ((CALayer *)self.showView.layer.presentationLayer).bounds;
self.showView.layer.backgroundColor = ((CALayer *)self.showView.layer.presentationLayer).backgroundColor;
self.showLabel.alpha = ((CALayer *)self.showLabel.layer.presentationLayer).opacity; // 移除之前的动画状态
[self.showView.layer removeAllAnimations]; // 做全新的动画
[UIView animateWithDuration:0.25f animations:^{
self.showView.bounds = CGRectMake(, , , );
self.showView.backgroundColor = [UIColor clearColor];
self.showLabel.alpha = .f;
} completion:^(BOOL finished) { }];
} - (void)scaleToDefault {
// 获取到当前的状态
self.showView.bounds = ((CALayer *)self.showView.layer.presentationLayer).bounds;
self.showView.layer.backgroundColor = ((CALayer *)self.showView.layer.presentationLayer).backgroundColor;
self.showLabel.alpha = ((CALayer *)self.showLabel.layer.presentationLayer).opacity; // 移除之前的动画状态
[self.showView.layer removeAllAnimations]; // 做全新的动画
[UIView animateWithDuration:0.25f animations:^{
self.showView.bounds = CGRectMake(, , , );
self.showView.backgroundColor = [UIColor clearColor];
self.showLabel.alpha = .f;
} completion:^(BOOL finished) { }];
} @end

核心源码:

编写带有点击特效的UIButton的更多相关文章

  1. Waves:类Material Design 的圆形波浪(涟漪)点击特效插件

    Waves:类Material Design 的圆形波浪(涟漪)点击特效插件 2014/08/06 分类:前端开发, 素材分享 浏览:6,734次  来源:原创 1个评论       6,734   ...

  2. 编写带对话框界面的OCX

    编写带对话框界面的OCX步骤: 1.添加Dialog资源,切换到资源视图,将对话框的Style设置为Child,在对话框界面右击添加类,输入类名MyDlg,使得其继承与CDialogEx.(继承CDi ...

  3. cnblogs鼠标点击特效

    喜大普奔! 伸手党福利 ! 创建mouse.js文件, 上传到博客, 直接引用即可, 内容如下: (function(window, document, undefined) { var hearts ...

  4. 用POP动画编写带富文本的自定义动画效果

    用POP动画编写带富文本的自定义动画效果 [源码] https://github.com/YouXianMing/UI-Component-Collection [效果] [特点] * 支持富文本 * ...

  5. javascript基础1 语法 点击事件 超链接带点击事件

    javascript ----------------------------------------------------------------------------------------- ...

  6. js鼠标点击特效,有关参数设置

    效果图,用的faststone--录像--togif,黄色圆圈实际是不显示的 博客后台管理设置 本地新建一个demo.html文件,可以自行测试,要引入jquery文件哦 来个“红橙黄绿蓝靛紫”的点击 ...

  7. jQuery 使用 jQuery UI 部件工厂编写带状态的插件(翻译)

    首先,我们要创建一个progress bar,它只允许我们简单的设置进度值.正如我们接下来将要看到的,我们需要通过调用 jQuery.widget 及其两个参数来实现这一操作,这两个参数分别是:将要创 ...

  8. [译]SSRS 编写带参数的MDX报表

    编写MDX报表长久以来对于报表人员来说都比较痛苦. 当然如果你用查询设计器(Query Designer) 直接拖拉数据集那就很方便,但是你们有没有想过查询设计器是怎么创建MDX的.或者创建的参数是如 ...

  9. Android5.0以上的项目都会有的按钮点击特效--水波纹

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...

随机推荐

  1. LDAP落地实战(一):OpenLDAP部署及管理维护

    公司内部会有许多第三方系统或服务,例如Svn,Git,VPN,Jira,Jenkins等等,每个系统都需要维护一份账号密码以支持用户认证,当然公司也会有许多的主机或服务器,需要开放登录权限给用户登录使 ...

  2. Java虚拟机(七):JVM调优案列

    Eclispe启动优化 概述 什么是jvm调优呢?jvm调优就是根据gc日志分析jvm内存分配.回收的情况来调整各区域内存比例或者gc回收的策略:更深一层就是根据dump出来的内存结构和线程栈来分析代 ...

  3. 桌面程序开发入门(WinForm with C#)

    1.使用Visual Studio 2013创建新项目 2.创建一个主窗体和4个子窗体 3.创建一个数据库.一个表.一个存储过程 4.在配置文件里添加数据库连接字符串 5.真正的编码工作. 第一步:创 ...

  4. Classpath entry org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER will not be exported or published

    sometimes when importing a maven project in eclipse, i get the following error: Classpath entry org. ...

  5. Content Negotiation using Spring MVC

    There are two ways to generate output using Spring MVC: You can use the RESTful @ResponseBody approa ...

  6. C#将Dll嵌入到EXE

    感谢博主的方法: https://blog.csdn.net/lin381825673/article/details/39122257 我之前也看了网上的其他的方法试了都不行 第一种方法就是说用IL ...

  7. jsonp跨域简单应用(一)

    转载:http://www.cnblogs.com/cyg17173/p/5865364.html ashx+jsonp+document.referrer   -- 一年前学的JSONP 跨域,一年 ...

  8. 自定义提醒视图Alert-动态绘制

    1. .h文件 #import <UIKit/UIKit.h> #define Wi [[UIScreen mainScreen]bounds].size.width #define He ...

  9. VS2015编译OpenSSL

    概述 OpenSSL 是一个开源的第三方库,它实现了 SSL(Secure SocketLayer)和 TLS(Transport Layer Security)协议,被广泛企业应用所采用.对于一般的 ...

  10. 【转】详解spring 每个jar的作用

    spring.jar 是包含有完整发布模块的单个jar 包.但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2. ...