Pregunta

Apple Shake annonced API en iPhone SDK 3.0. No puedo encontrar ninguna información con respecto a esta nueva función.

¿Quién sabe acerca de cómo usarlo? Cualquier ejemplo, enlace será bueno.

¿Fue útil?

Solución

Las API que buscas están en UIResponder :

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event;

En general, usted acaba de poner en práctica lo siguiente:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
  if (event.type == UIEventSubtypeMotionShake) {
    //Your code here
  }
}

en la subclase UIViewController (UIViewController es una subclase de UIResponder). Además, desea manejar en motionEnded: withEvent :, no motionBegan: withEvent :. motionBegan: withEvent: cuando se llama a los sospechosos de teléfono temblorosas que está sucediendo, pero el sistema operativo puede determinar la diferencia entre un usuario a propósito agitación, e incidental agitación (como subir las escaleras). Si el sistema operativo decide que no era una verdadera sacudida después de motionBegan: withEvent: se llama llamará motionCancelled: en lugar de motionEnded: withEvent:.

Otros consejos

he publicado un completo ejemplo 3.0 en este hilo:

¿Cómo puedo detectar cuando alguien sacude un iPhone?

Joe Hewitt recientemente cometido algo de código para Three20 que utiliza el evento 3.0 batido. Parece que sólo tiene que poner en práctica un código simple dentro de -motionBegan:withEvent: interior de su UIResponder .

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.type == UIEventSubtypeMotionShake) {
        ...
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top