Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added property for slider background view width #1

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions NGVolumeControl.podspec
@@ -0,0 +1,22 @@
Pod::Spec.new do |s|
s.platform = :ios, '6.0'
s.name = 'NGVolumeControl'
s.version = '1.0.0'
s.license = ''
s.summary = 'A custom (and customizable) volume control for iOS with a quick-gesture to change volume (touch down, slide finger, touch up).'
s.homepage = "http://pocketscience.com/"
s.source = { :git => 'https://pocketscience.com/scm/git/NGMoviePlayer' }
s.source_files = 'NGVolumeControl/*/*.{h,m}'
s.resource = 'NGMoviePlayer/Resources/NGMoviePlayer.bundle'
s.requires_arc = true
s.frameworks = 'Foundation', 'MediaPlayer'
s.authors = { 'PocketScience GmbH' => 'office@pocketscience.com'}

s.prefix_header_contents = '
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <QuartzCore/QuartzCore.h>
#endif
'
end
29 changes: 26 additions & 3 deletions NGVolumeControl/NGVolumeControl.xcodeproj/project.pbxproj
Expand Up @@ -145,7 +145,7 @@
9BCC745614FCCE8C004F30FF /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0450;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = "NOUS Wissensmanagement GmbH";
};
buildConfigurationList = 9BCC745914FCCE8C004F30FF /* Build configuration list for PBXProject "NGVolumeControl" */;
Expand Down Expand Up @@ -182,9 +182,16 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All @@ -194,10 +201,15 @@
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
Expand All @@ -206,13 +218,24 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
SDKROOT = iphoneos;
Expand Down
3 changes: 3 additions & 0 deletions NGVolumeControl/NGVolumeControl/NGVolumeControl.h
Expand Up @@ -29,6 +29,9 @@
/** The height of the expanded volume slider */
@property (nonatomic, assign) CGFloat sliderHeight UI_APPEARANCE_SELECTOR;

/** The width of the expanded volume slider background view */
@property (nonatomic, assign) CGFloat sliderBackgroundWidth;

/** The color of the slider track below the current value, defaults to white */
@property (nonatomic, strong) UIColor *minimumTrackColor UI_APPEARANCE_SELECTOR;
/** The color of the slider track above the current value, defaults to gray */
Expand Down
45 changes: 38 additions & 7 deletions NGVolumeControl/NGVolumeControl/NGVolumeControl.m
Expand Up @@ -11,7 +11,7 @@
#define kNGShadowRadius 10.f
#define kNGSlideDuration 0.2
#define kNGMinimumTapSize 44.f

#define kNGSliderBackgroundWidth 35.f

static MPVolumeView *ng_volumeView = nil;

Expand All @@ -22,6 +22,7 @@ @interface NGVolumeControl ()
@property (nonatomic, strong) UIView *sliderView;
@property (nonatomic, strong) NGVolumeSlider *slider;
@property (nonatomic, assign) float systemVolume;
@property (nonatomic, assign) float currentSystemVolume;
@property (nonatomic, readonly) BOOL sliderVisible;

@property (nonatomic, assign) CGPoint touchStartPoint;
Expand All @@ -44,6 +45,7 @@ - (id)initWithFrame:(CGRect)frame {
self.backgroundColor = [UIColor clearColor];

_sliderHeight = kNGSliderHeight;
_sliderBackgroundWidth = kNGSliderBackgroundWidth;
_expandDirection = NGVolumeControlExpandDirectionUp;
_expanded = NO;
_minimumTrackColor = [UIColor whiteColor];
Expand All @@ -60,7 +62,6 @@ - (id)initWithFrame:(CGRect)frame {

_sliderView = [[UIView alloc] initWithFrame:[self volumeViewFrameForExpandDirection:_expandDirection]];
_sliderView.backgroundColor = [UIColor clearColor];
_sliderView.contentMode = UIViewContentModeTop;
_sliderView.clipsToBounds = YES;
_sliderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

Expand All @@ -70,9 +71,9 @@ - (id)initWithFrame:(CGRect)frame {
panGesture.delaysTouchesEnded = YES;
[_sliderView addGestureRecognizer:panGesture];

_sliderBackgroundView = [[UIImageView alloc] initWithFrame:CGRectInset(_sliderView.bounds, 10.f, 0.f)];
CGFloat offset = (_sliderView.bounds.size.width - _sliderBackgroundWidth) / 2.f;
_sliderBackgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(offset, 0.f, _sliderBackgroundWidth, _sliderView.bounds.size.height)];
_sliderBackgroundView.image = [self imageForSliderBackgroundForExpandDirection:_expandDirection];
_sliderBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[_sliderView addSubview:_sliderBackgroundView];
[self hideSliderAnimated:NO];
[self addSubview:_sliderView];
Expand Down Expand Up @@ -101,6 +102,8 @@ - (id)initWithFrame:(CGRect)frame {

CGPathRelease(path);
}

self.currentSystemVolume = self.systemVolume;

// observe changes to system volume (volume buttons)
[[NSNotificationCenter defaultCenter] addObserver:self
Expand Down Expand Up @@ -288,10 +291,18 @@ - (void)setExpandDirection:(NGVolumeControlExpandDirection)expandDirection {
if (expandDirection != _expandDirection) {
_expandDirection = expandDirection;

self.slider.transform = [self transformForExpandDirection:expandDirection];
self.sliderView.frame = [self volumeViewFrameForExpandDirection:expandDirection];

self.sliderBackgroundView.image = [self imageForSliderBackgroundForExpandDirection:expandDirection];

if (expandDirection == NGVolumeControlExpandDirectionDown) {
self.sliderBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
self.sliderView.contentMode = UIViewContentModeTop;
} else {
self.sliderBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
self.sliderView.contentMode = UIViewContentModeBottom;
}

[self setSliderHeight:self.sliderHeight];
}
}

Expand All @@ -311,13 +322,22 @@ - (void)setMaximumTrackColor:(UIColor *)maximumTrackColor {
}
}

- (void)setSliderBackgroundWidth:(CGFloat)sliderBackgroundWidth {
if (sliderBackgroundWidth != _sliderBackgroundWidth) {
_sliderBackgroundWidth = sliderBackgroundWidth;

CGFloat offset = (_sliderView.bounds.size.width - _sliderBackgroundWidth) / 2.f;
_sliderBackgroundView.frame = CGRectMake(offset, 0.f, _sliderBackgroundWidth, _sliderView.bounds.size.height);
}
}

- (void)setSliderHeight:(CGFloat)sliderHeight {
if (sliderHeight != _sliderHeight) {
_sliderHeight = sliderHeight;
}

CGFloat offset = _expandDirection == NGVolumeControlExpandDirectionDown ? -5.f : 5.f;
CGFloat horizontalOffset = _expandDirection == NGVolumeControlExpandDirectionDown ? 0.5f : 0.f;
CGFloat horizontalOffset = _expandDirection == NGVolumeControlExpandDirectionDown ? 1.f : 0.f;

// Update UI to new height
[self hideSliderAnimated:NO];
Expand Down Expand Up @@ -388,7 +408,13 @@ - (void)customizeSlider:(UISlider *)slider {

- (void)setSystemVolume:(float)systemVolume {
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];

if ([self.volumeDelegate respondsToSelector:@selector(volumeControl:didChangeOldVolume:toNewVolume:)]) {
[self.volumeDelegate volumeControl:self didChangeOldVolume:musicPlayer.volume toNewVolume:systemVolume];
}

musicPlayer.volume = systemVolume;
self.currentSystemVolume = systemVolume;
}

- (float)systemVolume {
Expand Down Expand Up @@ -544,6 +570,11 @@ - (void)updateUI {

- (void)systemVolumeChanged:(NSNotification *)notification {
// we update the UI when the system volume changed (volume buttons)
if ([self.volumeDelegate respondsToSelector:@selector(volumeControl:didChangeOldVolume:toNewVolume:)]) {
float newVolume = [notification.userInfo[@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
[self.volumeDelegate volumeControl:self didChangeOldVolume:self.currentSystemVolume toNewVolume:newVolume];
self.currentSystemVolume = newVolume;
}
[self updateUI];
}

Expand Down
1 change: 1 addition & 0 deletions NGVolumeControl/NGVolumeControl/NGVolumeControlDelegate.h
Expand Up @@ -20,5 +20,6 @@
- (void)volumeControlDidExpand:(NGVolumeControl *)volumeControl;
- (void)volumeControlWillShrink:(NGVolumeControl *)volumeControl;
- (void)volumeControlDidShrink:(NGVolumeControl *)volumeControl;
- (void)volumeControl:(NGVolumeControl *)volumeControl didChangeOldVolume:(float)oldVolume toNewVolume:(float)newVolume;

@end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.