按钮在执行frame动画的时候怎么响应触发事件?
按钮在执行frame动画的时候怎么响应触发事件?

代码中效果(请注意,我并没有点击到按钮,而是点击到按钮的终点frame值处):

对应的代码:
//
// ViewController.m
// TapButton
//
// Created by YouXianMing on 14/12/7.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 初始化按钮
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
button.backgroundColor = [UIColor redColor];
[button addTarget:self
action:@selector(buttonEvent:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button]; // 执行动画
[UIView animateWithDuration:.f
delay:
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^{
button.frame = CGRectMake(, , , );
} completion:^(BOOL finished) { }];
} /**
* 按钮事件
*
* @param button 按钮事件
*/
- (void)buttonEvent:(UIButton *)button {
NSLog(@"YouXianMing");
} @end
修改过后的效果:

源码:
//
// ViewController.m
// TapButton
//
// Created by YouXianMing on 14/12/7.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "ChildView.h" @interface ViewController () { ChildView *tmpView; } @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 初始化按钮
tmpView = [[ChildView alloc] initWithFrame:CGRectMake(, , , )];
tmpView.backgroundColor = [UIColor redColor];
tmpView.userInteractionEnabled = NO; // 让self.view获取点击事件(穿透自身)
[self.view addSubview:tmpView]; // 执行动画
[UIView animateWithDuration:.f
delay:
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^{
tmpView.frame = CGRectMake(, , , );
} completion:^(BOOL finished) { }];
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// 获取点击点
CGPoint point = [[touches anyObject] locationInView:self.view]; // 获取tmpView的layer当前的位置
CGPoint presentationPosition = [[tmpView.layer presentationLayer] position]; // 判断位置,让tmpView接受点击事件
if (point.x > presentationPosition.x - && point.x < presentationPosition.x + &&
point.y > presentationPosition.y - && point.y < presentationPosition.y + ) {
[tmpView touchesBegan:touches withEvent:event];
}
} @end
ChildView.h 与 ChildView.m
//
// ChildView.h
// TapButton
//
// Created by YouXianMing on 14/12/7.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface ChildView : UIView @end
//
// ChildView.m
// TapButton
//
// Created by YouXianMing on 14/12/7.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "ChildView.h" @implementation ChildView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"获取点击事件");
} @end
关键性的两步:

按钮在执行frame动画的时候怎么响应触发事件?的更多相关文章
- Frame动画实战
Android动画分为Tween动画和Frame动画,Tween动画主要包括图片的放大缩小.旋转.透明度变化.移动等等操作:Frame动画则简单得多了,就是把一张张的图片连续播放产生动画效果. 本节主 ...
- android之frame动画详解
上一篇我们说了android中的tween动画,这一篇我们说说frame动画,frame动画主要是实现了一种类似于gif动画的效果,就是多张图按预先设定好的时间依次连续显示. 新建一个android项 ...
- 动画--问题追踪:ImageView执行缩放动画ScaleAnimation之后,图像显示不全的问题。
http://www.bkjia.com/Androidjc/929473.html: 问题追踪:ImageView执行缩放动画ScaleAnimation之后,图像显示不全的问题., 问题:我有一个 ...
- COCOS2D-X FRAME动画创作随笔
CCAnimate继承CCActionInterval,和CCAnimate是一家action,有着action所有的属性和方法. CCAnimate一些重要的方法: static CCAnimate ...
- [WPF] 动画Completed事件里获取执行该动画的UI对象
原文:[WPF] 动画Completed事件里获取执行该动画的UI对象 昨天群里有位童鞋提出如何在动画完成事件Completed里获取到执行该动画的UI对象. WPF里动画的Completed的本身并 ...
- GridView中的编辑和删除按钮,执行更新和删除代码之前的更新提示或删除提示
在GridView中,可以通过设计界面GridViewr任务->编辑列->CommandField,很简单的添加的编辑和删除按钮 在前台源码中,可以看到GridView自动生成了两个列. ...
- 消除点击连接或者按钮或者执行onclick事件时出现的边框
css中添加 *:not(input) { font-family: sans-serif; font-size-adjust: none; -webkit-user-select: none; -w ...
- 背水一战 Windows 10 (42) - 控件(导航类): Frame 动画
[源码下载] 背水一战 Windows 10 (42) - 控件(导航类): Frame 动画 作者:webabcd 介绍背水一战 Windows 10 之 控件(导航类) Frame 动画 示例An ...
- Android Frame动画demo
Android动画介绍:Android为我们提供了两种动画实现,Frame和Tween. 两者之间的区别: 1.Frame动画:就像放电影一样,是通过预先做好的图片进行连续播放从而形成动画效果 2.T ...
随机推荐
- 四大组件之Activity Task任务栈4种启动模式
1.启动模式 standard,创建一个新的Activity. singleTop,栈顶不是该类型的Activity,创建一个新的Activity.否则,onNewIntent. singleTask ...
- split使用和特殊使用(包括截取第一个字符后的数据)
javaScript中关于split()的使用 1.一般使用对一个字符串使用split(),返回一个数组 例子: var testArr = "1,2,3,4,5": var ...
- BackgroundWorker的简单用法
微软的官方例子 BackgroudWorker就是一个封装好的异步处理类(就是多线程,广泛用于winform开发中) 例子: 1.界面效果: 一个label,两个button 2.Form2.cs的代 ...
- Hadoop深入浅出实战经典视频教程(共22讲)
该视频教程共22讲,由王家林老师主讲. --------------------------------------------------------- 第01讲:为什么会有第一代大数据技术Hado ...
- R语言paste函数
中许多字符串使用 paste() 函数来组合.它可以将任意数量的参数组合在一起. 语法 粘贴(paste)函数的基本语法是: paste(..., sep = " ", colla ...
- C++实现顺序查找,折半查找,插值查找
1.顺序查找 从数组起始扫描到数组结尾,判断该索引数组是否和关键字相等,成功返回1 代码如下: //顺序查找 int seqSearch(int *array, int low, int high, ...
- Angular2-给属性做双向绑定
呈现一个实体对象的DOM结构,这个DOM有个自定义属性是需要动态赋值的,比如说 item.data 要绑到自定义属性 data 上:你可能会这么写: data="{{item.data}}& ...
- SQL Serever学习16——索引,触发器,数据库维护
sqlserver2014数据库应用技术 <清华大学出版社> 索引 这是一个很重要的概念,我们知道数据在计算机中其实是分页存储的,就像是单词存在字典中一样 数据库索引可以帮助我们快速定位数 ...
- Autocomplete 自动提示
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- Quartz大致介绍(一)
1. 介绍 Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,是完全由java开发的一个开源的任务日程管理系统,“任务进度管理器”就是一个在预先确定(被纳 ...