按钮在执行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(0, 0, 100, 100)];button.backgroundColor = [UIColor redColor];[button addTarget:selfaction:@selector(buttonEvent:)forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:button];// 执行动画[UIView animateWithDuration:10.fdelay:0options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteractionanimations:^{button.frame = CGRectMake(0, 468, 100, 100);} 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(0, 0, 100, 100)];tmpView.backgroundColor = [UIColor redColor];tmpView.userInteractionEnabled = NO; // 让self.view获取点击事件(穿透自身) [self.view addSubview:tmpView];// 执行动画[UIView animateWithDuration:10.fdelay:0options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteractionanimations:^{tmpView.frame = CGRectMake(0, 468, 100, 100);} 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 - 50 && point.x < presentationPosition.x + 50 &&point.y > presentationPosition.y - 50 && point.y < presentationPosition.y + 50) {[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
关键性的两步:
转载于:https://www.cnblogs.com/YouXianMing/p/4149103.html
按钮在执行frame动画的时候怎么响应触发事件?相关推荐
- android之frame动画详解
上一篇我们说了android中的tween动画,这一篇我们说说frame动画,frame动画主要是实现了一种类似于gif动画的效果,就是多张图按预先设定好的时间依次连续显示. 新建一个android项 ...
- HTML中button怎么填充GIF,css3给按钮添加背景渐变动画
css3给按钮添加背景渐变动画 button { color:#FFF; font-size:16px; outline:none; width:300px; height:48px; backgro ...
- 【Android】两种动画介绍(Tween动画、Frame动画)
Android中的动画类型有两种,一种是Tween动画.还有一种是Frame动画.Tween动画,这种实现方式可以使视图组件移动.放大.缩小以及产生透明度的变化;另一种Frame动画,传统的动画方法, ...
- 按钮背景过渡css3,使用CSS3点击按钮实现背景渐变动画的效果
这篇文章给大家介绍的是,利用CSS3实现当点击按钮的时候,按钮的背景是渐变动画的效果,实现后的效果非常好,开发的时候利用这种效果的按钮会给用户一种非常酷炫的感受,感兴趣的朋友们下面来一起看看吧. 效果 ...
- Animation Frame动画实现应用的欢迎界面
Android欢迎界面通常的实现可以通过Animation的Frame动画实现,ViewPager可以实现滑动效果的欢迎界面.本案例介绍Animation实现图示欢迎动画效果. (1)把准备好的图片放 ...
- 使用android frame动画定义自己的ProgressBar
使用android frame动画定义自己的ProgressBar 在 res /layout/ainm 目录下面建一个frame_ainm.xml文件 <?xml version=&quo ...
- Android Frame动画概述及示例
大家平时见到的最多的可能就是Frame动画了,Android中当然也少不了它.它的使用更加简单,只需要创建一个AnimationDrawabledF对象来表示Frame动画,然后通过addFrame ...
- qt同时两个动画执行_Qt 动画应用
Qt的动画机制,能用在QWidget.QGraphicWidget.以及在QML中也有部分应用的模型,这里只是先举两个小的例子,目前也没有太深入研究. 以QPropertyAnimation为例,在W ...
- 背水一战 Windows 10 (42) - 控件(导航类): Frame 动画
原文:背水一战 Windows 10 (42) - 控件(导航类): Frame 动画 [源码下载] 背水一战 Windows 10 (42) - 控件(导航类): Frame 动画 作者:webab ...
最新文章
- SPI、UART、I2C三种串行总线简介
- (0044) iOS 开发之SDWebImage 深度学习其源码和原理
- 央视曝光:刷单实为非法商业模式 步步设置全是套路
- 机房收费重构之总结篇
- 删除iptables nat 规则
- [翻译 EF Core in Action] 1.5 关于NoSql
- 力扣题目系列:474. 一和零
- 3811.排列-AcWing题库
- PID参数整定快速入门(调节器参数整定方法)
- 教你如何免费下载中国知网、万方学术论文?这份资源请收好!
- 我的博客生涯开始……
- c java gs_Java基础-gs(垃圾回收)
- HDMI热拔插电路举例说明
- 鸟哥的linux私房菜-基础学习篇 读书笔记
- 行为层JavaScript+jQuery
- 如何做好软文推广?如何写软文才可以精准引流?
- 【PyTorch基础】
- minisys-单周期cpu(一) 数据通路设计
- 锁相环(PLL)低杂散方案设想
- 订餐App回顾与总结