2011-10-14 36 views
9

Tengo una vista con UIButton, UITextField, y UIImageView para fondo.No se puede tocar durante la animación (Animación de bloque)

en viewDidLoad intente animar UIImageView de alfa = 0 a alfa = 1 usando bloque. es bastante básico, aquí está el código:

[UIView animateWithDuration:1.5 animations:^(void){ 

    ((UIView*)[self.view viewWithTag:123]).alpha = 1; 
}completion:^(BOOL finished){ 
}]; 

que funciona bien. pero durante esos 1.5 segundos de animación, mi toque en la vista actual parece estar deshabilitado. No puedo hacer clic en ninguno de los botones o textFields hasta que termine la animación.

Gracias de antemano

Respuesta

0

terminé no hacer esto. No puede tocar una vista que aún esté animando. esa es mi conclusión. Estaría feliz de escuchar algunos pensamientos sobre esto sin embargo.

29

Debe utilizar la opción UIViewAnimationOptionAllowUserInteraction como en el siguiente ejemplo:

[UIView animateWithDuration:1.0 
         delay:0 
        options:UIViewAnimationOptionAllowUserInteraction 
       animations:^{ myView.alpha = 0.5; } 
       completion:NULL]; 
+0

creo nada malo con mi código tan bien como el tuyo la diferencia solo tiene retraso y opciones. sin embargo, intentado, no funciona ... – HelmiB

+2

>> difieren solo en que tiene retraso y opciones. - Por favor, asegúrese de que no ajuste alfa a cero. Utilice al menos 0.1 en lugar de 0.0 'animaciones:^{myView.alpha = 0.1; } ' –

0

Uso animateWithDuration:delay:options:animations:completion: método y establecer UIViewAnimationOptionAllowUserInteraction como opción

+0

intentado, no funcionaba tan bien. parece que mi vista no funcionará durante la animación ... – HelmiB

+0

¿estás usando reconocedores de gestos? .. –

+0

No, solo vista normal ... – HelmiB

0

Parece que los botones de animación en general hacen que sus estados de clic sean bastante quisquillosos. La solución que surgió para esto fue hacer que el elemento de animación fuera solo una UIView con todos los estilos de botón. Antes de que el UIView se anime, agrego un botón real a la vista sobre UIView con un fondo claro para la ubicación en la que quiero que ocurra la interacción del usuario. Definitivamente agrega un paso extra pero es muy confiable.

//create button and view 
UIButton *viewNotificationBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, ([UIScreen mainScreen].bounds.size.height -70), 320, 50)]; 
UIView *viewNotificationView = [[UIView alloc] initWithFrame:CGRectMake(0, ([UIScreen mainScreen].bounds.size.height), 320, 50)]; 

//add elements to screen 
[self.view addSubview:viewNotificationView]; 
[self.view insertSubview:viewNotificationBtn aboveSubview:viewNotificationView]; 


[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ 
    [viewNotificationView setFrame:CGRectMake(0, ([UIScreen mainScreen].bounds.size.height - 70), 320, 50)]; 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.5 delay:10.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ 
     viewNotificationView.alpha = 0; 
    } completion:^(BOOL finished) { 
     [viewNotificationView removeFromSuperview]; 
     [viewNotificationBtn removeFromSuperview]; 
    }]; 
}]; 
2

userinteraction UIView en animación usando .allowUserInteraction para Swift + 3, el IOS 10

Añadir a la animación llamo los UIViewAnimationOptions bandera .allowUserInteraction

UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.0, options: [.curveEaseIn,.allowUserInteraction], animations: { 

      //your animation block 

      }, completion: { isAnimated in 
      //after animation is done 
    }) 
Cuestiones relacionadas