Exécuter une méthode après n secondes
La famille entière performSelector est vraiment intéressant et peut être utile dans une multitude de cas. Son application la plus simple et la plus courante est la suivante:
1 2 3 4 5 | @selector ( myMethod ) withObject : nil afterDelay : 3 ] ; [Self performSelector: @ selector (myMethod) withObject: afterDelay nul: 3]; / / void ) myMethod { - (Void) {myMethod "Hello World!" ) ; NSLog (@ "Bonjour le monde!"); } |
Cependant, considérer que le "timer" n'est pas exacte. Cette procédure devrait donc être utilisée quand il ya besoin d'une «importante» la précision temporelle.
Récupérer la version de la
1 2 |
OUI, vrai ou vrai?
e TRUE sono in pratica la stessa edentica cosa: Aller à coiffer grâce à l'iPhone d'Apple Kernel vous pouvez réaliser que YES , true , et TRUE sont fondamentalement les Édentia même chose:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | / / Définition du OUI # Définir OUI (BOOL) 1 # Ne pas définir de 0 (BOOL) / / Définition de la vraie # Définir une vraie # Définir 0 false / / Définition de VRAI # Si! Déterminées (TRUE) # Définir une VRAI # Endif # Si! Déterminées (FAUX) # Définir 0 FAUX # Endif |
Au moins pour l'instant ...
Vibrations
1 2 3 | # Import <AudioToolbox/AudioToolbox.h> / / ; AudioServicesPlaySystemSound (kSystemSoundID_Vibrate); |
Pointeur CGImageRef d'un UIImage
1 2 3 4 | [ UIImage imageNamed : @ "LittleHeart.png" ] ; UIImage * heart = [UIImage imageNamed: @ "LittleHeart.png"]; heart CGImage ] ; CGImageRef image = [CGImage coeur]; / / L'image peut désormais être "pixellisé" sur une CGContextRef CGRect ) { 0 , 0 , 100 , 100 } , image ) ; CGContextDrawImage (c, (CGRect) {0, 0, 100, 100}, image); |
Animations
1 2 3 4 5 | nil context : NULL ] ; [BeginAnimations UIView: contexte nul: NULL]; 1.5 ] ; [UIView setAnimationDuration: 1,5]; UIViewAnimationCurveEaseInOut ] ; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; / / ... ; [CommitAnimations UIView]; |
NSLog
1 2 3 | "NSString object %@ " , myString ) ; NSLog (@ "NSString objet% @", myString); "Float: %f " , myFloat ) ; NSLog (@ "float:% f", myFloat); "Integer: %i " , myInt ) ; NSLog (@ "Integer:% i", Myint); |
RGB convertisseur UIColor
1 | # Définir RGBA (r, g, b, a) [UIColor colorWithRed: r/255.0 vert: bleu g/255.0: b/255.0 alpha: a] |
Passer des paramètres à une NSTimer
Profitant du paramètre userInfo vous pouvez envoyer un pointeur vers un objet à notre méthode invoquée par minuterie.
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 cible: sélecteur de soi: @ selector (timerMethod) userInfo: répète objectPointer: YES]; / / ... void ) timerMethod : ( NSTimer * ) timer { - (Void) timerMethod: ( NSTimer *) timer { / / Récupérer le pointeur à mon objet timer userInfo ] ; objectPointer = [minuterie userInfo]; / / Ou myMethod ] ; [[Minuterie userInfo] myMethod]; [ [ timer userInfo ] myProperty ] ; int a = [[minuterie userInfo] myProperty]; / / Quel est le même [ objectPointer myProperty ] ; int a = [objectPointer myProperty]; } |
Durée
Voici une façon simple de calculer un court laps de temps nécessaire pour vérifier la vitesse d'exécution du code:
1 2 3 4 | ; CFAbsoluteTime initialTime CFAbsoluteTimeGetCurrent = (); / / ... queues ; CFAbsoluteTime finalTime CFAbsoluteTimeGetCurrent = (); "Tempo trascorso %f" , finalTime - initialTime ) ; NSLog (@ "f écoulé% du temps", finalTime - initialTime); |










Il n'y a aucun commentaire pour cet article
Laisser un commentaire