0

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

我将笔尖加载initWithFrame@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;
    }

之后我初始化视图并将其添加到主视图:

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

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

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

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        NSLog(@"touch");
    }

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

4

2 回答 2

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");}
于 2012-05-16T10:41:11.863 回答
0
[UIView beginAnimations:@"MoveAndStrech" context:nil];

[UIView setAnimationDuration:1];

[UIView setAnimationBeginsFromCurrentState:YES];

[UIView commitAnimations];
于 2012-05-16T10:28:44.757 回答