ViewController.h
@interface ViewController : UIViewController{
NSTimer *timer;
int MainInt;
IBOutlet UIButton *drag;
}
@property (weak, nonatomic) IBOutlet UILabel *l1;
- (IBAction)click:(id)sender;
-(void)countup;
- (IBAction)stopTimer:(id)sender;
- (IBAction)reset:(id)sender;
viewcontroller.M
-(void)countup {
MainInt += 1;
l1.text = [NSString stringWithFormat:@"%i", MainInt];
}
- (IBAction)click:(id)sender {
//MainInt = 0;
if (timer==nil)
{
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(countup)userInfo:nil repeats:YES];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[[event allTouches]anyObject];
drag.center=[touch locationInView:self.view];
}
- (IBAction)stopTimer:(id)sender
{
if (timer != nil)
{
[timer invalidate];
timer = nil;
}
}
- (IBAction)reset:(id)sender {
MainInt=0;
}
No comments:
Post a Comment