按钮在执行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. 几个用Python实现的简单算法

    一.算法题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去 掉不满足条件的排列. 程序源 ...

  2. MySQL的连接方式

    连接MySQL操作是连接进程和MySQL数据库实例进行通信.从开发的角度来说,本质上是进程通信.常用的进程通信方式有管道.命名管道.命名字.TCP/IP套接字.Unix域名套接字.MySQL提供的连接 ...

  3. WPF通过<x:Array>直接为ListBox的ItemsSource赋值

    <!--其中sys前缀是在xmlns中引入了System的命名空间--> <ListBox.ItemsSource> <x:Array Type="{x:Typ ...

  4. SpringCloud - 2. 服务注册 和 发现

    SpringCloud 的服务注册和发现是由Eureka来完成. 1.eureka server 1.1 依赖 <dependency> <groupId>org.spring ...

  5. rvm的安装, 使用rvm, 安装ruby, 以及gem的使用 (转)

    http://blog.163.com/digoal@126/blog/static/1638770402012425111617904/ rvm 全称Ruby Version Manager,  确 ...

  6. Mozilla新特性只支持https网站,再次推动SSL证书普及

    Mozilla的官方博客2015.4.30正式宣布了淘汰HTTP的方案. 其中包括:设定一个日期,所有的新特性将只提供给HTTPS网站:HTTP网站将逐步被禁止访问浏览器功能,尤其是那些与用户安全和隐 ...

  7. System.Web.HttpException: 请求在此上下文中不可用

    转自:https://www.cnblogs.com/wangguowen27/archive/2013/05/12/IIS_itcast_win7.html 问题:Web应用程序池配置错误造成的,这 ...

  8. CF898A Rounding

    题意翻译 给你一个数字,将其“四舍六入”,末尾为5舍去或进位都可,求最终的数字. 题目描述 Vasya has a non-negative integer n n n . He wants to r ...

  9. MVC中学到的小知识(MVC中的跳转,传参)

    1.mvc中视图中的href="XXX",这个XXX是控制器地址,不是另一个视图.(这里的href语句只能转向控制器,不能直接转向视图),如果要实现转向视图,可以先转到控制器,然后 ...

  10. SSM框架文件远程服务器下载

    1.首先你必须要建立连接 获取URL的输入流 2.之后就是文件读取和写入了 3.还有就是设置响应头,响应码等 代码 @RequestMapping("/fileDownLoad") ...