按钮在执行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动画的时候怎么响应触发事件?的更多相关文章

  1. Frame动画实战

    Android动画分为Tween动画和Frame动画,Tween动画主要包括图片的放大缩小.旋转.透明度变化.移动等等操作:Frame动画则简单得多了,就是把一张张的图片连续播放产生动画效果. 本节主 ...

  2. android之frame动画详解

    上一篇我们说了android中的tween动画,这一篇我们说说frame动画,frame动画主要是实现了一种类似于gif动画的效果,就是多张图按预先设定好的时间依次连续显示. 新建一个android项 ...

  3. 动画--问题追踪:ImageView执行缩放动画ScaleAnimation之后,图像显示不全的问题。

    http://www.bkjia.com/Androidjc/929473.html: 问题追踪:ImageView执行缩放动画ScaleAnimation之后,图像显示不全的问题., 问题:我有一个 ...

  4. COCOS2D-X FRAME动画创作随笔

    CCAnimate继承CCActionInterval,和CCAnimate是一家action,有着action所有的属性和方法. CCAnimate一些重要的方法: static CCAnimate ...

  5. [WPF] 动画Completed事件里获取执行该动画的UI对象

    原文:[WPF] 动画Completed事件里获取执行该动画的UI对象 昨天群里有位童鞋提出如何在动画完成事件Completed里获取到执行该动画的UI对象. WPF里动画的Completed的本身并 ...

  6. GridView中的编辑和删除按钮,执行更新和删除代码之前的更新提示或删除提示

    在GridView中,可以通过设计界面GridViewr任务->编辑列->CommandField,很简单的添加的编辑和删除按钮 在前台源码中,可以看到GridView自动生成了两个列. ...

  7. 消除点击连接或者按钮或者执行onclick事件时出现的边框

    css中添加 *:not(input) { font-family: sans-serif; font-size-adjust: none; -webkit-user-select: none; -w ...

  8. 背水一战 Windows 10 (42) - 控件(导航类): Frame 动画

    [源码下载] 背水一战 Windows 10 (42) - 控件(导航类): Frame 动画 作者:webabcd 介绍背水一战 Windows 10 之 控件(导航类) Frame 动画 示例An ...

  9. Android Frame动画demo

    Android动画介绍:Android为我们提供了两种动画实现,Frame和Tween. 两者之间的区别: 1.Frame动画:就像放电影一样,是通过预先做好的图片进行连续播放从而形成动画效果 2.T ...

随机推荐

  1. 【Maven学习】maven-assembly-plugin的使用

    转自http://liugang594.iteye.com/blog/2093607 maven-assembly-plugin使用描述(拷自 maven-assembly-plugin 主页) Th ...

  2. thinkPHP5配置nginx环境无法打开(require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s)

    今天想把玩一下tp5,结果怎么都无法访问,每次都是报500错误,我把错误提示都打开看到下面的错误 require(): open_basedir restriction in effect. File ...

  3. redis 持久化之 rdb 快照持久化

    解释1: 虽然redis是单进程,但是它有一个单独的子进程进行rdb操作,为了保证的数据的一致性,当进行rdb操作失败的时候,主进程就停止写入 所以才有了stop-write-on-bgsave-er ...

  4. 侵入式单链表的简单实现(cont)

    前一节介绍的侵入式链表实现在封装性方面做得不好,因为会让消费者foo.c直接使用宏container_of().这一节对list的定义做了一点改进,如下所示: typedef struct list_ ...

  5. Java泛型的基本使用

    Java1.5版本推出了泛型,虽然这层语法糖给开发人员带来了代码复用性方面的提升,但是这不过是编译器所做的一层语法糖,在真正生成的字节码中,这类信息却被擦除了.笔者发现很多几年开发经验的程序员,依然不 ...

  6. echarts实现自动轮播tooltip

    最近需要实现echarts图形中hover效果轮播(即tooltip在各个数据点上轮流显示)的功能,以下就是我学习的一个过程,只是提供思路,具体场景需要自己修改.(仅针对echarts 2.2.7及以 ...

  7. springmvc fileupload

    1.pom文件中fileupload的dependencyyinr <dependency> <groupId>commons-fileupload</groupId&g ...

  8. jQuery基础---动画效果

    内容摘要: 1.显示.隐藏 2.滑动.卷动 3.淡入.淡出 4.自定义动画 5.列队动画方法 6.动画相关方法 7.动画全局属性  发文不易,转载请注明出处~ 一.显示.隐藏 jQuery 中显示方法 ...

  9. Docker学习之Docker镜像基本使用

    Docker学习之Docker镜像基本使用 获取镜像 命令格式:docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] 例如: docker pull ...

  10. 百度搜索URL参数含义

    序号 参数 含义 1 tn 搜索框所属网站.比如 tn=sitehao123,就是 http://www.hao123.com/ 左上那个搜索框(指通过什么方式到达百度首页搜索界面;) 2 s?wd ...