从笔尖加载的视图不会接收触摸事件

时间:2012-05-16 10:22:26

标签: iphone ios nib loadnibnamed

我正在尝试从笔尖加载视图并将其添加到主视图中。这是我的代码。

我将笔尖加载到initWithFrame的{​​{1}}:

@interface AddTaskView:UIView

之后我启动视图并将其添加到主视图中:

 - (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;
    }

一切正常但AddTaskView没有收到触摸事件。我有三个按钮,当我尝试推动它们时,他们没有收到动作。 我做了“AddTaskView”类型的笔尖,但没有任何运气。我还查看了子视图,“AddTaskView”是顶视图。

我在AddTaskView中添加了这段代码,看看我是否触摸并且没有响应:

 self.addTaskView=[[AddTaskView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
    [self.view addSubview:self.addTaskView];

我如何有机会回应触摸事件?

2 个答案:

答案 0 :(得分:0)

[UIView beginAnimations:@"MoveAndStrech" context:nil];

[UIView setAnimationDuration:1];

[UIView setAnimationBeginsFromCurrentState:YES];

[UIView commitAnimations];

答案 1 :(得分:0)

我认为你必须注册一个触摸调度员,然后尝试触摸....以下是该代码

-(void)registerWithTouchDispatcher{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0swallowsTouches:YES];}

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
return YES;}

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
touchLocation = [touch  locationInView:[touch view]];
NSLog(@"Touch is working");}
相关问题