Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

tvos - UIButton blocking touchesBegan and touchesMoved

I'm writing an app for tvOS - and it all works until I put a UIButton on the screen. The problem, when buttons are added, is that touchesBegan and touchesMoved stop working. If I remove the buttons then touchesBegan and touchesMoved start working correctly again. I have tried, in the interests of experimentation, unchecking 'User Interaction Enabled' - but this didn't make any difference. I have also tried subclassing UIButton and adding the following code:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [self.nextResponder touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];
    [self.nextResponder touchesMoved:touches withEvent:event];
}

Sadly this doesn't seem to work either. Does anyone have any suggestions as to what I might try next?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According to this answer, the button becomes a focused view and it's getting all the touches. You have to make your view (in which you implement touchesBegan and touchesMoved) focusable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...