Skip to content

Commit

Permalink
fix rendering on iOS7 (compiled against SDK 7 or SDK 6), closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
HBehrens committed Jul 16, 2013
1 parent b84b118 commit 24863eb
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ BeamMusicPlayerExample.xcodeproj/project.xcworkspace/xcuserdata/
BeamMusicPlayerExample.xcworkspace/xcuserdata/
Pods/Pods.xcodeproj/xcuserdata
Documentation/html
BeamMusicPlayerExample.xcworkspace/xcshareddata
84 changes: 69 additions & 15 deletions Source/BeamMusicPlayerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ -(IBAction)sliderValueChanged:(id)slider;
@property (nonatomic,weak) IBOutlet UILabel* scrobbleHelpLabel; // The Scrobble Usage hint Label
@property (nonatomic,weak) IBOutlet UILabel* numberOfTracksLabel; // Track x of y or the scrobble speed
@property (nonatomic,weak) IBOutlet UIImageView* scrobbleHighlightShadow; // It's reflection
@property (nonatomic,weak) IBOutlet UIImageView *scrobbleBackgroundImage;

@property(nonatomic,weak) IBOutlet UIView* controlView;

Expand Down Expand Up @@ -170,21 +171,25 @@ - (void)viewDidLoad
self.coverArtGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(coverArtTapped:)];
[self.albumArtImageView addGestureRecognizer:self.coverArtGestureRecognizer];
} else {
//on ipad use shadow behind cover art
self.albumArtImageView.layer.shadowColor = [UIColor blackColor].CGColor;
self.albumArtImageView.layer.shadowOpacity = 0.8;
self.albumArtImageView.layer.shadowRadius = 10.0;
self.albumArtImageView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
self.albumArtImageView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.albumArtImageView.bounds].CGPath;


if(!self.isIOS7) {
//on ipad use shadow behind cover art
self.albumArtImageView.layer.shadowColor = [UIColor blackColor].CGColor;
self.albumArtImageView.layer.shadowOpacity = 0.8;
self.albumArtImageView.layer.shadowRadius = 10.0;
self.albumArtImageView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
self.albumArtImageView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.albumArtImageView.bounds].CGPath;
}
}
}

// Progess Slider
UIImage* knob = [UIImage imageNamed:@"BeamMusicPlayerController.bundle/images/VolumeKnob"];
[progressSlider setThumbImage:knob forState:UIControlStateNormal];
progressSlider.maximumTrackTintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
UIImage* minImg = [[UIImage imageNamed:@"BeamMusicPlayerController.bundle/images/speakerSliderMinValue.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
UIImage* maxImg = [[UIImage imageNamed:@"BeamMusicPlayerController.bundle/images/speakerSliderMaxValue.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
[progressSlider setMinimumTrackImage:minImg forState:UIControlStateNormal];
[progressSlider setMaximumTrackImage:maxImg forState:UIControlStateNormal];

// Volume Slider
volumeViewContainer.backgroundColor = [UIColor clearColor];
Expand All @@ -200,8 +205,6 @@ - (void)viewDidLoad
[volumeViewContainer addSubview:notSupportedLabel];
}
#else
UIImage* minImg = [[UIImage imageNamed:@"BeamMusicPlayerController.bundle/images/speakerSliderMinValue.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
UIImage* maxImg = [[UIImage imageNamed:@"BeamMusicPlayerController.bundle/images/speakerSliderMaxValue.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
// Since there is a bug/glitch in iOS with setting the thumb, we need to use an image with 5pt transparency at the bottom
UIImage* knobImg = [UIImage imageNamed:@"BeamMusicPlayerController.bundle/images/mpSpeakerSliderKnob.png"];
[self.volumeView setVolumeThumbImage:knobImg forState:UIControlStateNormal];
Expand Down Expand Up @@ -247,6 +250,25 @@ - (void)viewDidLoad
[self.trackTitleLabel setShadowColor:[UIColor blackColor]];
[self.trackTitleLabel setShadowOffset:CGSizeMake(0, -1)];
}

if(self.isIOS7) {
CGFloat statusBarHeight = UIApplication.sharedApplication.statusBarFrame.size.height;
self.navigationBar.frame = CGRectOffset(self.navigationBar.frame, 0, statusBarHeight);
self.navigationBar.tintColor = UIColor.whiteColor;
CGRect f = self.artworkPlaylistContainer.frame;
f.origin.y += statusBarHeight;
f.size.height -= statusBarHeight;
self.artworkPlaylistContainer.frame = f;
if(self.isTallPhone) {
self.artworkPlaylistContainer.backgroundColor = UIColor.clearColor;
self.scrobbleHighlightShadow.hidden = YES;
self.scrobbleBackgroundImage.hidden = YES;
}

self.controlsToolbar.tintColor = UIColor.whiteColor;
self.progressSlider.frame = CGRectOffset(self.progressSlider.frame, 0, -3);
}

self.placeholderImageDelay = 0.5;


Expand Down Expand Up @@ -276,6 +298,7 @@ - (void)viewDidUnload
{
self.actionButton = nil;
self.backButton = nil;
[self setScrobbleBackgroundImage:nil];
[super viewDidUnload];
self.coverArtGestureRecognizer = nil;
// Release any retained subviews of the main view.
Expand All @@ -297,17 +320,24 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
CGFloat statusBarHeight = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? UIApplication.sharedApplication.statusBarFrame.size.width : UIApplication.sharedApplication.statusBarFrame.size.height;
CGFloat dy = self.isIOS7 ? statusBarHeight : 0;
CGRect f = self.albumArtImageView.frame;
f.origin.x = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 65 : 84;
f.origin.y = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? (int)((self.view.bounds.size.height-self.navigationBar.bounds.size.height-f.size.height)/2)+self.navigationBar.bounds.size.height : 65;
f.origin.x = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 65 + dy : 84;
f.origin.y = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? (int)((self.view.bounds.size.height-self.navigationBar.bounds.size.height-f.size.height)/2)+self.navigationBar.bounds.size.height : 65 + dy;
self.albumArtImageView.frame = f;

f = self.controlView.frame;
f.size.width = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 350 : 600;
f.origin.x = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 660 : 84;
f.origin.y = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 220 : 675;
f.origin.x = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 660 + dy : 84;
f.origin.y = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 220 : 675 + dy;
self.controlView.frame = f;

// workaround: on iOS7 the progress slider grows while rotating, force size
f = self.progressSlider.frame;
f.size.width = self.controlView.bounds.size.width - 2 * f.origin.x;
self.progressSlider.frame = f;

}
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
Expand All @@ -332,6 +362,29 @@ -(BOOL)isIOS5_0 {
return ([UIDevice.currentDevice.systemVersion compare:@"5.1" options:NSNumericSearch]) == NSOrderedAscending;
}

-(BOOL)isIOS7 {
NSLog(@"__IPHONE_OS_VERSION_MAX_ALLOWED: %d", __IPHONE_OS_VERSION_MAX_ALLOWED);
NSLog(@"__IPHONE_6_1: %d", __IPHONE_6_1);
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
return ([UIDevice.currentDevice.systemVersion compare:@"7" options:NSNumericSearch]) >= NSOrderedSame;
#else
return NO;
#endif
}


#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1

-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}

- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar {
return UIBarPositionTopAttached;
}
#endif


-(BOOL)isTallPhone {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && (screenSize.height > 480.0f);
Expand Down Expand Up @@ -887,8 +940,9 @@ -(void)setScrobbleUI:(BOOL)scrobbleState animated:(BOOL)animated{
/*
* Action triggered by the continous track progress slider
*/
-(IBAction)sliderValueChanged:(id)slider {
-(IBAction)sliderValueChanged:(UISlider*)slider {
self->currentPlaybackPosition = self.progressSlider.value;
NSLog(@"slider.controlState: %@", slider.currentMinimumTrackImage);
[self updateUIForScrubbingSpeed: self.progressSlider.scrubbingSpeed];

if ( [self.delegate respondsToSelector:@selector(musicPlayer:didSeekToPosition:)]) {
Expand Down
66 changes: 62 additions & 4 deletions Source/BeamMusicPlayerViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1296</int>
<string key="IBDocument.SystemVersion">11G63</string>
<string key="IBDocument.SystemVersion">12E55</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1138.51</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<string key="IBDocument.AppKitVersion">1187.39</string>
<string key="IBDocument.HIToolboxVersion">626.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">2083</string>
Expand Down Expand Up @@ -797,6 +797,14 @@
</object>
<int key="connectionID">113</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="146668208"/>
<reference key="destination" ref="372490531"/>
</object>
<int key="connectionID">114</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">titleView</string>
Expand Down Expand Up @@ -1206,7 +1214,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">113</int>
<int key="maxID">114</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -1230,11 +1238,32 @@
<string key="className">BeamMusicPlayerViewController</string>
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="actionButtonAction:">id</string>
<string key="backButtonAction:">id</string>
<string key="coverArtTapped:">id</string>
<string key="nextAction:">id</string>
<string key="playAction:">id</string>
<string key="playlistButtonTapped:">id</string>
<string key="previousAction:">id</string>
<string key="repeatModeButtonAction:">id</string>
<string key="shuffleButtonAction:">id</string>
<string key="sliderDidBeginScrubbing:">id</string>
<string key="sliderDidEndScrubbing:">id</string>
<string key="sliderValueChanged:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="actionButtonAction:">
<string key="name">actionButtonAction:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="backButtonAction:">
<string key="name">backButtonAction:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="coverArtTapped:">
<string key="name">coverArtTapped:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="nextAction:">
<string key="name">nextAction:</string>
<string key="candidateClassName">id</string>
Expand All @@ -1243,6 +1272,30 @@
<string key="name">playAction:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="playlistButtonTapped:">
<string key="name">playlistButtonTapped:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="previousAction:">
<string key="name">previousAction:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="repeatModeButtonAction:">
<string key="name">repeatModeButtonAction:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="shuffleButtonAction:">
<string key="name">shuffleButtonAction:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="sliderDidBeginScrubbing:">
<string key="name">sliderDidBeginScrubbing:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="sliderDidEndScrubbing:">
<string key="name">sliderDidEndScrubbing:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="sliderValueChanged:">
<string key="name">sliderValueChanged:</string>
<string key="candidateClassName">id</string>
Expand All @@ -1268,6 +1321,7 @@
<string key="repeatButton">UIButton</string>
<string key="rewindButton">UIBarButtonItem</string>
<string key="rewindButtonIPad">UIButton</string>
<string key="scrobbleBackgroundImage">UIImageView</string>
<string key="scrobbleHelpLabel">UILabel</string>
<string key="scrobbleHighlightShadow">UIImageView</string>
<string key="scrobbleOverlay">UIView</string>
Expand Down Expand Up @@ -1355,6 +1409,10 @@
<string key="name">rewindButtonIPad</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo" key="scrobbleBackgroundImage">
<string key="name">scrobbleBackgroundImage</string>
<string key="candidateClassName">UIImageView</string>
</object>
<object class="IBToOneOutletInfo" key="scrobbleHelpLabel">
<string key="name">scrobbleHelpLabel</string>
<string key="candidateClassName">UILabel</string>
Expand Down
Loading

0 comments on commit 24863eb

Please sign in to comment.