从笔尖加载的视图不接收触摸事件 [英] A view loaded from the nib doesn't receive touch events
问题描述
我正在尝试从笔尖加载视图并将其添加到主视图.这是我的代码.
I am trying to load a a view from the nib and add it to the main view. Here is my code.
我将笔尖装入了@interface AddTaskView:UIView
的initWithFrame
中:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"init with frame");
// Initialization code
NSArray *addTaskArrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"AddTaskView"
owner:self
options:nil];
self=[addTaskArrayOfViews objectAtIndex:0];
}
return self;
}
之后,我初始化视图并将其添加到主视图中:
After that I init the view and add it to the main view:
self.addTaskView=[[AddTaskView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:self.addTaskView];
一切正常,但是AddTaskView没有收到touch事件.我有三个按钮,当我尝试按下它们时,它们没有收到动作. 我做了"AddTaskView"类型的笔尖,但是没有任何运气.我还查看了子视图,"AddTaskView"是顶视图.
Everything works fine but the AddTaskView doesn't receive the touch event. I have three buttons and when I try to push them they don't receive the actions. I made the nib of type "AddTaskView" but without any luck. I also looked in the subviews and the "AddTaskView" is the top view.
我在AddTaskView中添加了此代码,以查看是否触摸并且没有响应:
I added this code in the AddTaskView to see if I get a touch and no response:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touch");
}
如何获得响应触摸事件的机会?
How do I get a chance to respond to touch events?
推荐答案
[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView commitAnimations];
这篇关于从笔尖加载的视图不接收触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!