Ejecutar un método después de n segundos
Toda la familia performSelector es muy interesante y puede ser útil en una multitud de casos. Su aplicación más simple y más común es la siguiente:
1 2 3 4 5 | @selector ( myMethod ) withObject : nil afterDelay : 3 ] ; [Self performSelector: @ selector (myMethod) withObject: afterDelay nil: 3]; / / void ) myMethod { - (Void) myMethod { "Hello World!" ) ; NSLog (@ "Hello World!"); } |
Sin embargo, tenga en cuenta que el "timer" no es exacta. Este procedimiento, por lo tanto, se debe utilizar cuando no se solicita una precisión temporal "significativo".
Recuperar la versión de la aplicación
1 2 |
Sí, es cierto o falso?
e TRUE sono in pratica la stessa edentica cosa: Ir a peinar el Apple iPhone Kernel puede darse cuenta de que YES , true y TRUE edentica son básicamente la misma cosa:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | / / Definición de la SI # Definir SI (BOOL) 1 # Definir NO (BOOL) 0 / / Definición de la verdadera # Definir verdadera 1 # Definir false 0 / / Definición de VERDADERO # Si! Defined (TRUE) # Definir VERDADERO 1 # Endif # Si! Defined (FALSO) # Se define FALSO 0 # Endif |
Al menos por ahora ...
Charla
1 2 3 | # Importar <AudioToolbox/AudioToolbox.h> / / ; AudioServicesPlaySystemSound (kSystemSoundID_Vibrate); |
CGImageRef Puntero de un UIImage
1 2 3 4 | [ UIImage imageNamed : @ "LittleHeart.png" ] ; UIImage * heart = [UIImage imageNamed: @ "LittleHeart.png"]; heart CGImage ] ; CGImageRef image = [corazón CGImage]; / / La imagen se puede ahora "rasterizar" en CGContextRef CGRect ) { 0 , 0 , 100 , 100 } , image ) ; CGContextDrawImage (c, (CGRect) {0, 0, 100, 100}, imagen); |
Animaciones
1 2 3 4 5 | nil context : NULL ] ; [UIView beginAnimations: contexto nil: NULL]; 1.5 ] ; [UIView setAnimationDuration: 1,5]; UIViewAnimationCurveEaseInOut ] ; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; / / ... ; [CommitAnimations UIView]; |
NSLog
1 2 3 | "NSString object %@ " , myString ) ; NSLog (@ "NSString objeto% @", miCadena); "Float: %f " , myFloat ) ; NSLog (@ "float:% f", myFloat); "Integer: %i " , myInt ) ; NSLog (@ "Integer:% i", myInt); |
Convertidor de RGB a UIColor
1 | # Definir RGBA (r, g, b, a) [UIColor colorWithRed: r/255.0 verde: azul g/255.0: b/255.0 alpha: a] |
Paso de parámetros a una NSTimer
Aprovechando el parámetro userInfo puedes enviar un puntero a un objeto al método invocado por el temporizador.
1 2 3 4 5 6 7 8 9 10 11 12 13 | scheduledTimerWithTimeInterval : 1 target : self selector : @selector ( timerMethod ) userInfo : objectPointer repeats : YES ] ; [ NSTimer scheduledTimerWithTimeInterval: 1 objetivo: Selector auto: @ selector (timerMethod) userInfo: objectPointer repite: YES]; / / ... void ) timerMethod : ( NSTimer * ) timer { - (Void) timerMethod: ( NSTimer *) timer { / / Recuperar el puntero al objeto timer userInfo ] ; objectPointer = [temporizador userInfo]; / / O myMethod ] ; [[Timer userInfo] myMethod]; [ [ timer userInfo ] myProperty ] ; int a = [[temporizador userInfo] myProperty]; / / Que es lo mismo [ objectPointer myProperty ] ; int a = [objectPointer myProperty]; } |
Tiempo de ejecución
Aquí está una manera fácil de calcular corto tiempo necesario para comprobar la velocidad de ejecución del código:
1 2 3 4 | ; CFAbsoluteTime initialTime CFAbsoluteTimeGetCurrent = (); / / ... código ; CFAbsoluteTime finalTime CFAbsoluteTimeGetCurrent = (); "Tempo trascorso %f" , finalTime - initialTime ) ; NSLog (@ "Tiempo transcurrido% f", finalTime - initialTime); |










No hay comentarios para este post
Deja un comentario