从笔尖加载的观点不接收触摸事件(A view loaded from the nib doesn&#

2019-09-17 06:55发布

我试图从笔尖加载AA视图,并把它添加到主视图。 这里是我的代码。

我装在笔尖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");
    }

我如何得到一个机会来响应触摸事件?

Answer 1:

我认为你必须注册一个触摸调度程序,然后试图让触摸....下面是该代码

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


Answer 2:

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

[UIView setAnimationDuration:1];

[UIView setAnimationBeginsFromCurrentState:YES];

[UIView commitAnimations];


文章来源: A view loaded from the nib doesn't receive touch events