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

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

按钮在执行frame动画的时候怎么响应触发事件?_第1张图片

#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


你可能感兴趣的:(按钮在执行frame动画的时候怎么响应触发事件?)