按鈕在執行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


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容