Pregunta

Sé que esta es una pregunta muy comúnmente se hacen, pero todas las respuestas en todos los sitios web no hacer el trabajo! Si todavía no sabe lo que quiero decir, entonces tal vez esta línea de código le ayudará a entender.


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:self.view];
    if (touch.view == nextbutton)
        [self performSelector:@selector(next)];
    if (touch.view == prevbutton)
        [self performSelector:@selector(previous)];
    if (touch.view == moreoptionsbutton)
        [self performSelector:@selector(moresettings)];
}

No hace nada cuando se toca nextbutton, prevbutton, and more optionsbutton, que son UIImageViews por cierto. También he intentado usar isEqual: en lugar de ==, pero que no ha funcionado bien. ¿Alguna sugerencia?

¿Fue útil?

Solución

Usted tiene que fijar userinteractionEnabled = SÍ para todas sus UIImageViews de lo contrario no recibirán eventos táctiles. También cambiar la línea:

 UITouch *touch = [[event allTouches] anyObject];

a

 UITouch *touch = [touches anyObject];

Otros consejos

He creado una comprobación para asegurarse de su la vista espero ser hecho clic antes de continuar.

if( [touch.view isKindOfClass:[Custom class]] ){
    CGPoint touchPoint = [touch locationInView:self.view];

    if( CGRectContainsPoint( self.customClassOne.frame, touchPoint )
       || CGRectContainsPoint( self.customClassTwo.frame, touchPoint ) ){
        [self touchOnCustomClass];
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top