Je crée une application qui est essentiellement une extension d'un tutoriel (je suis très nouveau dans le monde du développement d'applications). Le tutoriel avait une boîte de couleur cyan se déplaçant autour de l'écran au point où vous touchez. Ce que j'ai fait a été de changer l'arrière-plan en un ImageView afin qu'il ressemble à la mer profonde et j'ai mis un ImageView dans le UIView cyan pour afficher la silhouette blanche d'un plongeur. Ce que je veux de cette expérience/exercice est de faire apparaître et disparaître des bulles toutes les deux secondes, à la fois chez le plongeur et l'algue en bas de l'écran.Application iPhone: Créer un objet toutes les secondes
Je configure mon minuteur en utilisant ce Quickie link mais je reçois toutes sortes d'erreurs de la déclaration NSTimer.
Voici mon code:
NSTimer *bubbleTimer;
bubbleTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
target: bubble
selector: @selector(moveBubble:)
userInfo: nil
repeats: YES];
La ligne NSTimer * bubbleTimer; ne colore pas le NSTimer, et une erreur indique qu'il est par défaut bubbleTimer à un int.
Comme je l'ai dit, je suis encore à essayer de trouver mes pieds dans ce monde de sorte que toute aide que vous pouvez donner sera apprécié
EDIT:
ici est mon .h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface TouchView : UIView {
IBOutlet UIView *stretchView; //This defines an object in Interface Builder called stretchView
IBOutlet UIView *bubble;
NSTimer *bubbleTimer;
}
@end
et mon .m
#import "TouchView.h"
@implementation TouchView
//First we need a method that processes each touch of the screen
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//Begin an animation - The animation is given a name which in this case is
//Move and Stretch
[UIView beginAnimations:@"MoveAndStretch" context:nil];
//We set a duration for this animation in seconds
[UIView setAnimationDuration:1];
//Start the animation from the screen's current state
[UIView setAnimationBeginsFromCurrentState:YES];
//Any location changes between here and Commit Animations is animated.
//Firstly we need to process a simple touch which
if([touches count] == 1) {
//make a single touch variable
UITouch *touch = [touches anyObject];
//change the location of stretchview to the location of the touch
stretchView.center = [touch locationInView:self];
}
[UIView commitAnimations];
}
- (void)moveBubble:(NSTimer *)theTimer {
CGPoint start;
start.x=480;
start.y=300;
CGPoint end;
end.x=0;
end.y=300;
bubble.center=start;
[UIView beginAnimations:@"Bubble" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationBeginsFromCurrentState:YES];
bubble.center=end;
[UIView commitAnimations];
}
bubbleTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
target: self
selector: @selector(moveBubble:)
userInfo: nil
repeats: YES];
@end
Ça a l'air ok. Est-ce un fichier .m-obj et inclut les en-têtes appropriés? Peut-être partager toute la méthode. – Eiko