diff --git a/ios/SubtleVolume.h b/ios/SubtleVolume.h index 642e5ef1f804..32899f7a9e96 100644 --- a/ios/SubtleVolume.h +++ b/ios/SubtleVolume.h @@ -77,6 +77,7 @@ typedef NS_ENUM(NSInteger, SubtleVolumeAnimation) { @property (nonatomic, strong) UIColor *barTintColor; @property (nonatomic, assign) id delegate; @property (nonatomic, assign) BOOL animatedByDefault; +@property (nonatomic, assign) CGFloat padding; - (instancetype)initWithStyle:(SubtleVolumeStyle)style; - (instancetype)initWithStyle:(SubtleVolumeStyle)style frame:(CGRect)frame; diff --git a/ios/SubtleVolume.mm b/ios/SubtleVolume.mm index 80de327df369..6c02939100c8 100644 --- a/ios/SubtleVolume.mm +++ b/ios/SubtleVolume.mm @@ -79,7 +79,6 @@ - (void)setup { } volumeLevel = [[AVAudioSession sharedInstance] outputVolume]; -// [self updateVolume:[[AVAudioSession sharedInstance] outputVolume] animated:NO]; [[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew context:NULL]; [volume setVolumeThumbImage:[[UIImage alloc] init] forState:UIControlStateNormal]; [volume setUserInteractionEnabled:NO]; @@ -94,15 +93,18 @@ - (void)setup { - (void)layoutSubviews { [super layoutSubviews]; - overlay.frame = self.frame; - overlay.frame = CGRectMake(0, 0, self.frame.size.width*volumeLevel, self.frame.size.height); + overlay.frame = CGRectMake( + self.padding, + self.padding, + (self.frame.size.width - (self.padding*2)) * volumeLevel, + self.frame.size.height - (self.padding*2) + ); self.backgroundColor = self.barBackgroundColor; overlay.backgroundColor = self.barTintColor; } - (void)updateVolume:(CGFloat)value animated:(BOOL)animated { - NSLog(@"updateVolume: value:%f animated:%@", value, animated?@"YES":@"NO"); [self.delegate subtleVolume:self willChange:value]; volumeLevel = value; lastAnimated = animated; @@ -119,27 +121,17 @@ - (void)updateVolume:(CGFloat)value animated:(BOOL)animated { self.timer = nil; } - NSLog(@"Spinning up timer with timeInterval 2 ..."); self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerComplete) userInfo:nil repeats:NO]; - [self doShow:animated]; - [self.delegate subtleVolume:self didChange:value]; } - (void)timerComplete { - NSLog(@"timerComplete!"); [self doHide:lastAnimated]; self.timer = nil; } - (void)doHide:(BOOL)animated { - NSLog(@"doHide:%@, runningShowAnimation: %@, runningHideAnimation: %@, showing: %@", - animated?@"YES":@"NO", - runningShowAnimation?@"YES":@"NO", - runningHideAnimation?@"YES":@"NO", - showing?@"YES":@"NO"); - if(!showing) { return; } @@ -169,12 +161,10 @@ - (void)doHide:(BOOL)animated { break; } } completion:^(BOOL finished) { - NSLog(@"Hide animation complete; finished? %@", finished?@"YES":@"NO"); showing = NO; runningHideAnimation = NO; }]; } else { - NSLog(@"Hide immediate complete."); showing = NO; self.alpha = 0.0001; if(self.animation == SubtleVolumeAnimationSlideDown) { @@ -184,12 +174,6 @@ - (void)doHide:(BOOL)animated { } - (void)doShow:(BOOL)animated { - NSLog(@"doShow:%@, runningShowAnimation: %@, runningHideAnimation: %@, showing: %@", - animated?@"YES":@"NO", - runningShowAnimation?@"YES":@"NO", - runningHideAnimation?@"YES":@"NO", - showing?@"YES":@"NO"); - if(showing) { return; } @@ -203,6 +187,12 @@ - (void)doShow:(BOOL)animated { } if(animated) { + // set up for first run, assuming the animation has changed + // between instantiation and first showing + if(self.animation == SubtleVolumeAnimationSlideDown) { + self.transform = CGAffineTransformMakeTranslation(0, -self.frame.size.height); + } + runningShowAnimation = YES; [UIView animateWithDuration:0.333 animations:^{ switch (self.animation) { @@ -219,12 +209,10 @@ - (void)doShow:(BOOL)animated { break; } } completion:^(BOOL finished) { - NSLog(@"Show animation complete; finished? %@", finished?@"YES":@"NO"); showing = YES; runningShowAnimation = NO; }]; } else { - NSLog(@"Show immediate complete."); showing = YES; self.alpha = 1; self.transform = CGAffineTransformIdentity; diff --git a/ios/ViewController.mm b/ios/ViewController.mm index f57048410b4b..94192cc3a346 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -136,10 +136,8 @@ -(id) init { } - (void)subtleVolume:(SubtleVolume *)volumeView willChange:(CGFloat)value { -// NSLog(@"%f alpha: %f", value, volumeView.alpha); } - (void)subtleVolume:(SubtleVolume *)volumeView didChange:(CGFloat)value { -// NSLog(@"END %f alpha: %f", value, volumeView.alpha); } - (void)viewDidLoad { @@ -210,10 +208,20 @@ - (void)viewDidLoad { } #endif - volume = [[SubtleVolume alloc] initWithStyle:SubtleVolumeStylePlain frame:CGRectMake(10, 0, self.view.frame.size.width-20, 4)]; - // volume.animatedByDefault = NO; - volume.barTintColor = [UIColor whiteColor]; - volume.barBackgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.3]; + CGFloat margin = 0; + CGFloat height = 16; + volume = [[SubtleVolume alloc] + initWithStyle:SubtleVolumeStylePlain + frame:CGRectMake( + margin, // X + 0, // Y + self.view.frame.size.width-(margin*2), // width + height // height + )]; + + volume.padding = 7; + volume.barTintColor = [UIColor blackColor]; + volume.barBackgroundColor = [UIColor whiteColor]; volume.animation = SubtleVolumeAnimationSlideDown; volume.delegate = self; [self.view addSubview:volume];