按钮在执行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 ...
随机推荐
- php 判断字符串之间包含关系
之前常用stristr , strpos判断. 因为处理1000W * 1000W级别,循环就是漫长漫长... 在此,对stristr, strpos, explode判断字符串包含关系处理速度对比 ...
- TensorFlow架构与设计:概述
TensorFlow是什么? TensorFlow基于数据流图,用于大规模分布式数值计算的开源框架.节点表示某种抽象的计算,边表示节点之间相互联系的张量. TensorFlow支持各种异构的平台,支持 ...
- 入门系列之在Ubuntu 14.04上备份,还原和迁移MongoDB数据库
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由信姜缘 发表于云+社区专栏 MongoDB是最受欢迎的NoSQL数据库引擎之一.它以可扩展,强大,可靠和易于使用而闻名.在本文中,我们 ...
- vs2015 点击cshtml 后提示 "无效指针" 的解决办法
1. 关闭vs 2. 删除 %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache 3. 打开vs OK 解决
- 数据库命令行操作语句 linux 详细
1.连接数据库 命令: use <数据库名> 2.查看表的引擎类型等状态信息 SHOW TABLE STATUS [FROMdb_name] [LIKE 'pattern'] 3.当前数据 ...
- 关于PHP数据库mysql的一些案例
案例1:查询select 使用php连接数据库class9, 获取数据库的表student中的信息, 然后输出到页面上(用表格套住) <?php header("Content-typ ...
- shell脚本生成服务器密码
#!/bin/bash len=90 str=(a b c d e f g h i j k l m n o p q r s t u vw x y z A B C D E F G H I J K L M ...
- python 爬虫入门案例----爬取某站上海租房图片
前言 对于一个net开发这爬虫真真的以前没有写过.这段时间开始学习python爬虫,今天周末无聊写了一段代码爬取上海租房图片,其实很简短就是利用爬虫的第三方库Requests与BeautifulSou ...
- Ubuntu重启网卡的三种方法
一.network利用root帐户# service network restart 或者/etc/init.d/networking restart 二.ifdown/ifup# ifdown et ...
- sql:MySql create FUNCTION,VIEW,PROCEDURE
use geovindu; #函数 DELIMITER $$ drop function if exists f_GetDepartmentName $$ CREATE function f_GetD ...