SHOW:
|
|
- or go back to the newest paste.
| 1 | @implementation ViewController | |
| 2 | ||
| 3 | - (void)viewDidLoad {
| |
| 4 | [super viewDidLoad]; | |
| 5 | // Do any additional setup after loading the view, typically from a nib. | |
| 6 | ||
| 7 | elapsed = 0; | |
| 8 | numOfSpeed = 120; | |
| 9 | ||
| 10 | UIButton *playBtn = [[UIButton alloc] initWithFrame:CGRectMake(200, 200, 50, 50)]; | |
| 11 | [playBtn setTitle:@"Play" forState:UIControlStateNormal]; | |
| 12 | playBtn.backgroundColor = UIColor.redColor; | |
| 13 | [playBtn addTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside]; | |
| 14 | [self.view addSubview:playBtn]; | |
| 15 | ||
| 16 | UIButton *incrementBtn = [[UIButton alloc] initWithFrame:CGRectMake(250, 200, 50, 50)]; | |
| 17 | [incrementBtn setTitle:@"+" forState:UIControlStateNormal]; | |
| 18 | incrementBtn.backgroundColor = UIColor.redColor; | |
| 19 | [incrementBtn addTarget:self action:@selector(incrementButton:) forControlEvents:UIControlEventTouchUpInside]; | |
| 20 | [self.view addSubview:incrementBtn]; | |
| 21 | ||
| 22 | UIButton *decrementBtn = [[UIButton alloc] initWithFrame:CGRectMake(150, 200, 50, 50)]; | |
| 23 | [decrementBtn setTitle:@"-" forState:UIControlStateNormal]; | |
| 24 | decrementBtn.backgroundColor = UIColor.redColor; | |
| 25 | [decrementBtn addTarget:self action:@selector(decrementButton:) forControlEvents:UIControlEventTouchUpInside]; | |
| 26 | [self.view addSubview:decrementBtn ]; | |
| 27 | ||
| 28 | self.label = [[UILabel alloc] initWithFrame:CGRectMake(200, 300, 100, 100)]; | |
| 29 | self.label.text = [NSString stringWithFormat:@"%.0f", numOfSpeed]; | |
| 30 | self.label.backgroundColor = UIColor.blueColor; | |
| 31 | [self.view addSubview:_label]; | |
| 32 | ||
| 33 | [self configureSwipeRecognizerWithDirection:UISwipeGestureRecognizerDirectionUp]; | |
| 34 | - | UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)]; |
| 34 | + | [self configureSwipeRecognizerWithDirection:UISwipeGestureRecognizerDirectionDown]; |
| 35 | - | UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)]; |
| 35 | + | [self configureSwipeRecognizerWithDirection:UISwipeGestureRecognizerDirectionLeft]; |
| 36 | - | UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)]; |
| 36 | + | [self configureSwipeRecognizerWithDirection:UISwipeGestureRecognizerDirectionRight]; |
| 37 | - | UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)]; |
| 37 | + | |
| 38 | - | [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; |
| 38 | + | |
| 39 | - | [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; |
| 39 | + | |
| 40 | - | [swipeUp setDirection:UISwipeGestureRecognizerDirectionUp]; |
| 40 | + | } |
| 41 | - | [swipeDown setDirection:UISwipeGestureRecognizerDirectionDown]; |
| 41 | + | |
| 42 | - | [swipeLeft setNumberOfTouchesRequired:1]; |
| 42 | + | - (void)configureSwipeRecognizerWithDirection:(UISwipeGestureRecognizerDirection)direction {
|
| 43 | - | [swipeRight setNumberOfTouchesRequired:1]; |
| 43 | + | UISwipeGestureRecognizer * recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)]; |
| 44 | - | [swipeUp setNumberOfTouchesRequired:1]; |
| 44 | + | recognizer.direction = direction; |
| 45 | - | [swipeDown setNumberOfTouchesRequired:1]; |
| 45 | + | recognizer.numberOfTouchesRequired = 1; |
| 46 | - | [self.view addGestureRecognizer:swipeLeft]; |
| 46 | + | [self.view addGestureRecognizer:recognizer]; |
| 47 | - | [self.view addGestureRecognizer:swipeUp]; |
| 47 | + |