cuando ingresamos una contraseña incorrecta en un programa que necesita contraseña en OSX, la ventana tiembla ¿cómo puedo implementarla en mi programa?sacudir ventana cuando el usuario ingrese la contraseña incorrecta del código
Respuesta
utilizar por debajo de código cuando el usuario introduce una contraseña incorrecta
static int numberOfShakes = 8;
static float durationOfShake = 0.5f;
static float vigourOfShake = 0.05f;
CGRect frame=[self.view.window frame];
CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animation];
CGMutablePathRef shakePath = CGPathCreateMutable();
CGPathMoveToPoint(shakePath, NULL, NSMinX(frame), NSMinY(frame));
int index;
for (index = 0; index < numberOfShakes; ++index)
{
CGPathAddLineToPoint(shakePath, NULL, NSMinX(frame) - frame.size.width * vigourOfShake, NSMinY(frame));
CGPathAddLineToPoint(shakePath, NULL, NSMinX(frame) + frame.size.width * vigourOfShake, NSMinY(frame));
}
CGPathCloseSubpath(shakePath);
shakeAnimation.path = shakePath;
shakeAnimation.duration = durationOfShake;
[self.view.window setAnimations:[NSDictionary dictionaryWithObject: shakeAnimation forKey:@"frameOrigin"]];
[[self.view.window animator] setFrameOrigin:[self.view.window frame].origin];
que estoy loco por bloques. Aquí hay una versión bloque que se debe trabajar, también ...
- (void)shakeView:(UIView *)view times:(NSInteger)times completion:(void (^)(BOOL finished))completion {
if (times <= 0) {
completion(YES);
} else {
UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState;
[UIView animateWithDuration:0.1 delay: 0.0 options: options
animations:^{
view.frame = CGRectOffset(view.frame, 6.0, 0.0); // shake to
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.1 delay: 0.0 options:options
animations:^{
view.frame = CGRectOffset(view.frame, -6.0, 0.0); // shake fro
}
completion:^(BOOL finished) {
[self shakeView:view times:times-1 completion:completion];
}];
}];
}
}
aquí es @ respuesta de SajjadZare en Swift:
Swift 2.0:
let numberOfShakes:Int = 8
let durationOfShake:Float = 0.5
let vigourOfShake:Float = 0.05
let frame:CGRect = (self.view.window?.frame)!
let shakeAnimation = CAKeyframeAnimation()
let shakePath = CGPathCreateMutable()
CGPathMoveToPoint(shakePath, nil, NSMinX(frame), NSMinY(frame))
for _ in 1...numberOfShakes {
CGPathAddLineToPoint(shakePath, nil, NSMinX(frame) - frame.size.width * CGFloat(vigourOfShake), NSMinY(frame))
CGPathAddLineToPoint(shakePath, nil, NSMinX(frame) + frame.size.width * CGFloat(vigourOfShake), NSMinY(frame))
}
CGPathCloseSubpath(shakePath)
shakeAnimation.path = shakePath
shakeAnimation.duration = CFTimeInterval(durationOfShake)
self.view.window?.animations = ["frameOrigin":shakeAnimation]
self.view.window?.animator().setFrameOrigin(self.view.window!.frame.origin)
Swift 3.0:
let numberOfShakes:Int = 8
let durationOfShake:Float = 0.5
let vigourOfShake:Float = 0.05
let frame:CGRect = (self.view.window!.frame)
let shakeAnimation = CAKeyframeAnimation()
let shakePath = CGMutablePath()
shakePath.move(to: CGPoint(x: NSMinX(frame), y: NSMinY(frame)))
for _ in 1...numberOfShakes {
shakePath.addLine(to: CGPoint(x:NSMinX(frame) - frame.size.width * CGFloat(vigourOfShake), y: NSMinY(frame)))
shakePath.addLine(to: CGPoint(x:NSMinX(frame) + frame.size.width * CGFloat(vigourOfShake), y: NSMinY(frame)))
}
shakePath.closeSubpath()
shakeAnimation.path = shakePath
shakeAnimation.duration = CFTimeInterval(durationOfShake)
self.view.window?.animations = ["frameOrigin":shakeAnimation]
self.view.window?.animator().setFrameOrigin((self.view.window?.frame.origin)!)
swift 3.0 tal vez? – dylan
@dylan Se ha actualizado. – iwatakeshi
¿Esto va en el controlador de vista o el controlador de ventana (si existe?) – dylan
Esta es la forma en que lo hice:
-(void)shakeLayer:(CALayer*)layer{
int repeats = 4;
float time = 0.04;
float movement = 5;
for(int x = 0; x < repeats; x++){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(x*(time*4) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
CABasicAnimation *posAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
[posAnimation setFromValue:[NSNumber numberWithFloat:0]];
[posAnimation setToValue:[NSNumber numberWithFloat:movement]];
[posAnimation setBeginTime:0.0];
[posAnimation setDuration:time];
CABasicAnimation *negAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
[negAnimation setFromValue:[NSNumber numberWithFloat:movement]];
[negAnimation setToValue:[NSNumber numberWithFloat:-movement]];
[negAnimation setBeginTime:time];
[negAnimation setDuration:time*2];
CABasicAnimation *posAnimation2 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
[posAnimation2 setFromValue:[NSNumber numberWithFloat:-movement]];
[posAnimation2 setToValue:[NSNumber numberWithFloat:0]];
[posAnimation2 setBeginTime:time*3];
[posAnimation2 setDuration:time];
CAAnimationGroup *group = [CAAnimationGroup animation];
[group setDuration:time*4];
[group setAnimations:[NSArray arrayWithObjects:posAnimation, negAnimation, posAnimation2, nil]];
[layer addAnimation:group forKey:nil];
});
}
}
- 1. ¿Qué sucede cuando escribo la contraseña incorrecta?
- 2. Ingrese la contraseña en C
- 3. UIAlertView ingrese el ID y la contraseña de Apple IAP
- 4. ¿Por qué `sudo` es lento cuando la contraseña es incorrecta?
- 5. ¿Cómo evitar que el usuario ingrese decimales?
- 6. Oracle: ¿cómo desactivar la contraseña del usuario?
- 7. El depurador de Eclipse ejecuta la versión incorrecta del código
- 8. Error de inicio de sesión: nombre de usuario desconocido o contraseña incorrecta
- 9. Permitir solo 1 carácter en EditText y sobrescribir siempre cuando el usuario lo ingrese
- 10. Cómo ocultar ventana emergente de Gtk cuando el usuario hace clic fuera de la ventana
- 11. Visual Studio haciendo clic en Buscar resultados abre el código en ventana incorrecta
- 12. ¿Cuál es la duración óptima para la contraseña del usuario?
- 13. ¿Cómo agregar sal en la contraseña del usuario?
- 14. animando UITextField para indicar una contraseña incorrecta
- 15. ¿Cómo recibir una notificación cuando un usuario cambia la contraseña o solicita un restablecimiento de contraseña?
- 16. Ingrese texto en EditText que luego desaparece cuando el usuario hace clic dentro de él
- 17. Cómo deshabilitar la ventana emergente predeterminada de la contraseña del navegador?
- 18. Selenio usando Python: ingrese/proporcione la contraseña http proxy para firefox
- 19. Utilice ALTER LOGIN para cambiar la propia contraseña del usuario
- 20. Cambiar la contraseña de usuario de Linux del script PHP
- 21. Restauración del usuario y la contraseña 'root' eliminados para MySQL
- 22. Recuperar la contraseña del usuario actual de spring-security
- 23. AndroidDebugKey Keystore fue manipulado, o la contraseña era incorrecta
- 24. La mejor manera de hacer código para "Contraseña olvidada"
- 25. Estoy usando Rails3 con tinymce. ¿Cómo presentar el navegador del usuario javascript, luego ingrese xss?
- 26. Nombre de usuario no encontrado o mensaje de error de contraseña incorrecta demasiado vago
- 27. Tengo una contraseña encriptada con md5, ¿cómo darle la contraseña al usuario cuando usa "Olvidé mi contraseña"?
- 28. primavera: programáticamente ingrese
- 29. Enviar formulario cuando ingrese la tecla presionada con Prototype javascript
- 30. javascript para verificar cuando la ventana del navegador está cerca
anterior utiliza la vista, [aquí] (http://stackoverflow.com/questions/10517386/how-to-shake-nswindow/23491643#23491643) sacude la ventana. * No es un gran cambio, pero solo para una referencia fácil * –