我已經創建了一個UIView編程按鈕點擊這樣touchesBegan無法在iOS中使用UIView?
self.paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height+100)];
[self.paintView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]];
[self.navigationController.view addSubview:self.paintView];
,並補充說,navigationController
這樣我就可以看到我在全屏的UIView。
但是當我試圖來檢測觸摸它不工作
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if (touch.view==self.paintView && self.paintView) {
[UIView animateWithDuration:0.9 animations:^{
[self.sideView setFrame:CGRectMake(-290, 0, self.sideView.frame.size.width, self.sideView.frame.size.height)];
}];
}
}
這種方法不是現在在所有的檢測。
這是因爲您使用通過代碼創建的一些新視圖阻止父視圖,touches方法屬於父視圖,但由於子視圖無法檢測到它。 – Dasem