iphone ios animation ios4 uiimageview

iphone - ¿Cómo cancelar la animación basada en bloques de UIView?



ios animation (3)

Agregaría a la respuesta de Nick que para hacer removeAllAnimations la próxima idea sea muy útil.

[view.layer removeAllAnimations]; [UIView transitionWithView:self.redView duration:1.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ [view.layer displayIfNeeded]; } completion:nil];

He buscado un montón de cosas SO y en las referencias de Apple, pero todavía no puedo administrar mi problema.

Lo que tengo:

  1. pantalla con 2 UIImageViews nad conectado con ellos 2 UIButtons
  2. 2 tipos de animación:
    2.1. el primero escala, luego baja cada imagen, una tras otra, solo una vez en viewDidLoad 2.2. el segundo, cuando se presiona el botón (que es un botón personalizado, se oculta "dentro" de cada UIImageView), se activa la animación del UIImageView apropiado - solo uno, no ambos - (también escala hacia arriba, luego hacia abajo).
  3. ¡Mientras escribo para iOS4 +, me dicen que use animaciones basadas en bloques!

Lo que necesito:

¿Cómo cancelar la ejecución de la animación? Pude cancelar después de todo, pero el último ...: / Aquí está mi fragmento de código:

[UIImageView animateWithDuration:2.0 delay:0.1 options:UIViewAnimationOptionAllowUserInteraction animations:^{ isAnimating = YES; self.bigLetter.transform = CGAffineTransformScale(self.bigLetter.transform, 2.0, 2.0); } completion:^(BOOL finished){ if(! finished) return; [UIImageView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ self.bigLetter.transform = CGAffineTransformScale(self.bigLetter.transform, 0.5, 0.5); } completion:^(BOOL finished){ if(! finished) return; [UIImageView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ self.smallLetter.transform = CGAffineTransformScale(self.smallLetter.transform, 2.0, 2.0); } completion:^(BOOL finished){ if(! finished) return; [UIImageView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ self.smallLetter.transform = CGAffineTransformScale(self.smallLetter.transform, 0.5, 0.5); } completion:^(BOOL finished){ if (!finished) return; //block letter buttons [self.bigLetterButton setUserInteractionEnabled:YES]; [self.smallLetterButton setUserInteractionEnabled:YES]; //NSLog(@"vieDidLoad animations finished"); }]; }]; }]; }];

De alguna manera, smallLetter UIImageView no funciona correctamente, ya que al presionarlo (a través del botón), BigLetter cancela las animaciones correctamente ... gracias de antemano :)

EDITAR: He utilizado esta solución, pero aún tengo problemas para reducir SmallLetter UIImageView, sin cancelar nada ... solution

EDIT2: He agregado esto al comienzo de los métodos next / prev:

- (void)stopAnimation:(UIImageView*)source { [UIView animateWithDuration:0.01 delay:0.0 options:(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction) animations:^ { source.transform = CGAffineTransformIdentity; } completion:NULL ]; }

el problema se queda ...: no tengo idea de cómo interrumpir la última animación de las letras en la cadena de animación


Para iOS 10 usa UIViewPropertyAnimator para animar. Proporciona métodos para iniciar, detener y pausar animaciones de UIView.

let animator = UIViewPropertyAnimator(duration: 2.0, curve: .easeOut){      self.view.alpha = 0.0 } // Call this to start animation. animator.startAnimation() // Call this to stop animation. animator.stopAnimation(true)


Puede detener todas las animaciones en una vista llamando a:

[view.layer removeAllAnimations];

(Necesitarás importar el framework QuartzCore para llamar a los métodos en view.layer).

Si desea detener una animación específica, no todas las animaciones, su mejor opción es utilizar CAAnimations explícitamente en lugar de los métodos de ayuda de animación de UIView, luego tendrá un control más detallado y podrá detener las animaciones explícitamente por su nombre.

La documentación de Apple Core Animation se puede encontrar aquí:

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/CreatingBasicAnimations/CreatingBasicAnimations.html