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

http://www.cnblogs.com/YouXianMing/p/4149103.html

#import"ViewController.h"#import"ChildView.h"@interfaceViewController ()

{

ChildView*tmpView;

}@end@implementationViewController- (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.f

delay:0options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionAllowUserInteraction

animations:^{

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


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容