Here's the code I wrote that uses the normalization function and displays the current speed (and a play icon that resizes to fit the playerβs speed:
- (IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateBegan) { [self.rateLabel setHidden:FALSE]; [self animatePlayerControl:@"β·" size:1.0]; [UIView animateWithDuration:0.375 animations:^{ (self.playerControlsLabel).alpha = 0.5f; }]; } else if (sender.state == UIGestureRecognizerStateEnded) { [self.rateLabel setHidden:FALSE]; // set to TRUE after testing or remove hiding altogether //[self.delegate setRate:oldRate]; //[self animatePlayerControl:@"β‘" size:1.0]; //[_ChromaEpsilonGammaAppDelegate.playerViewController setRate:0.0]; //[_ChromaEpsilonGammaAppDelegate.playerViewController stop]; [UIView animateWithDuration:0.375 animations:^{ (self.playerControlsLabel).alpha = 0.0f; }]; } else if (sender.state == UIGestureRecognizerStateChanged){ CGPoint location = [sender locationInView:self]; float nlx = ((location.x / ((CGRectGetMidX(self.frame) / (self.frame.size.width / 2.0)))) / (self.frame.size.width / 2.0)) - 1.0; //float nly = ((location.y / ((CGRectGetMidY(self.view.frame) / (self.view.frame.size.width / 2.0)))) / (self.view.frame.size.width / 2.0)) - 1.0; nlx = nlx * 2.0; [self.delegate setRate:nlx]; if (nlx > 0.0) [self animatePlayerControl:@"β·" size:nlx]; else if (nlx < 0.0) [self animatePlayerControl:@"β" size:fabs(nlx)]; (self.rateLabel).text = [NSString stringWithFormat:@"%.2f", [self.delegate rate]]; } }
Setting up a label that can go anywhere, and not just with the drawRect method:
- (void)drawRect:(CGRect)rect { (self.brightnessLabel).textColor = [UIColor colorWithWhite:1.0 alpha:1.0]; (self.brightnessLabel).font = [UIFont preferredFontForTextStyle:@"Apple Symbol"]; (self.brightnessLabel).textAlignment = NSTextAlignmentCenter; (self.contrastLabel).textColor = [UIColor colorWithWhite:1.0 alpha:1.0]; (self.contrastLabel).font = [UIFont preferredFontForTextStyle:@"Apple Symbol"]; (self.contrastLabel).textAlignment = NSTextAlignmentCenter; _attrsDictionary = @{NSFontAttributeName: [UIFont systemFontOfSize:24.0 weight:UIFontWeightLight]}; }
And, the player icon auto-tuning code:
- (void)animatePlayerControl:(NSString *)labelText size:(float)size { (self.playerControlsLabel).textColor = [UIColor colorWithWhite:1.0 alpha:1.0]; (self.playerControlsLabel).font = [UIFont preferredFontForTextStyle:@"Apple Symbol"]; (self.playerControlsLabel).textAlignment = NSTextAlignmentCenter; NSDictionary *attrsDictionary = @{NSFontAttributeName: [UIFont systemFontOfSize:fabs(48.0 * size) weight:UIFontWeightUltraLight]}; NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:labelText attributes:attrsDictionary]; (self.playerControlsLabel).attributedText = attrString; }
A player icon is simply a symbol from the Apple Symbol font.
source share