filmov
tv
iPhone Programming - How to create a 'hold down' button

Показать описание
An Xcode 4 tutorial teaching you how to create a "hold down" button so when they are "holding" it down the action carries on and when they let go the action stops.
Main Code:
In the .h:
IBOutlet UIImageView *image;
NSTimer *goUp;
NSTimer *goDown;
NSTimer *goLeft;
NSTimer *goRight;
}
-(IBAction)down; //Conected to "touch down"
-(IBAction)stopDown; //Connected tp "touchUpInside"
-(IBAction)up; //Conected to "touch down"
-(IBAction)stopUp; //Connected tp "touchUpInside"
-(IBAction)left; //Conected to "touch down"
-(IBAction)stopLeft; //Connected tp "touchUpInside"
-(IBAction)right; //Conected to "touch down"
-(IBAction)stopRight; //Connected tp "touchUpInside"
-(void)goDown;
-(void)goUp;
-(void)goLeft;
-(void)goRight;
In the .m
-(IBAction)down {
if (goDown == nil) {
}
}
-(IBAction)stopDown {
[goDown invalidate];
goDown = nil;
}
-(IBAction)up {
if (goUp == nil) {
}
}
-(IBAction)stopUp {
[goUp invalidate];
goUp = nil;
}
-(IBAction)left {
if (goLeft == nil) {
}
}
-(IBAction)stopLeft {
[goLeft invalidate];
goLeft = nil;
}
-(IBAction)right {
if (goRight == nil) {
}
}
-(IBAction)stopRight {
[goRight invalidate];
goRight = nil;
}
-(void)goDown {
}
-(void)goUp {
}
-(void)goLeft {
}
-(void)goRight {
}
Main Code:
In the .h:
IBOutlet UIImageView *image;
NSTimer *goUp;
NSTimer *goDown;
NSTimer *goLeft;
NSTimer *goRight;
}
-(IBAction)down; //Conected to "touch down"
-(IBAction)stopDown; //Connected tp "touchUpInside"
-(IBAction)up; //Conected to "touch down"
-(IBAction)stopUp; //Connected tp "touchUpInside"
-(IBAction)left; //Conected to "touch down"
-(IBAction)stopLeft; //Connected tp "touchUpInside"
-(IBAction)right; //Conected to "touch down"
-(IBAction)stopRight; //Connected tp "touchUpInside"
-(void)goDown;
-(void)goUp;
-(void)goLeft;
-(void)goRight;
In the .m
-(IBAction)down {
if (goDown == nil) {
}
}
-(IBAction)stopDown {
[goDown invalidate];
goDown = nil;
}
-(IBAction)up {
if (goUp == nil) {
}
}
-(IBAction)stopUp {
[goUp invalidate];
goUp = nil;
}
-(IBAction)left {
if (goLeft == nil) {
}
}
-(IBAction)stopLeft {
[goLeft invalidate];
goLeft = nil;
}
-(IBAction)right {
if (goRight == nil) {
}
}
-(IBAction)stopRight {
[goRight invalidate];
goRight = nil;
}
-(void)goDown {
}
-(void)goUp {
}
-(void)goLeft {
}
-(void)goRight {
}
Комментарии