Skip to content

Commit

Permalink
Merge pull request #8 from bcylin/feature/support-rotation
Browse files Browse the repository at this point in the history
Support Device Rotation
  • Loading branch information
sgryschuk committed Apr 5, 2014
2 parents 621bbc9 + a3df694 commit 958974f
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 207 deletions.
6 changes: 6 additions & 0 deletions SGNavigationProgress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
45E7625F17EC9535005838A5 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 45E7625D17EC9535005838A5 /* InfoPlist.strings */; };
45E7626117EC9535005838A5 /* SGNavigationProgressTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E7626017EC9535005838A5 /* SGNavigationProgressTests.m */; };
45E7626D17EC9593005838A5 /* UINavigationController+SGProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E7626C17EC9593005838A5 /* UINavigationController+SGProgress.m */; };
B5EC426518D94F6A001FE164 /* SGProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = B5EC426418D94F6A001FE164 /* SGProgressView.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -56,6 +57,8 @@
45E7626017EC9535005838A5 /* SGNavigationProgressTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SGNavigationProgressTests.m; sourceTree = "<group>"; };
45E7626B17EC9593005838A5 /* UINavigationController+SGProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UINavigationController+SGProgress.h"; sourceTree = "<group>"; };
45E7626C17EC9593005838A5 /* UINavigationController+SGProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UINavigationController+SGProgress.m"; sourceTree = "<group>"; };
B5EC426318D94F6A001FE164 /* SGProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGProgressView.h; sourceTree = "<group>"; };
B5EC426418D94F6A001FE164 /* SGProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGProgressView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -161,6 +164,8 @@
children = (
45E7626B17EC9593005838A5 /* UINavigationController+SGProgress.h */,
45E7626C17EC9593005838A5 /* UINavigationController+SGProgress.m */,
B5EC426318D94F6A001FE164 /* SGProgressView.h */,
B5EC426418D94F6A001FE164 /* SGProgressView.m */,
);
path = "UINavigationController+SGProgress";
sourceTree = "<group>";
Expand Down Expand Up @@ -263,6 +268,7 @@
buildActionMask = 2147483647;
files = (
45E7624C17EC9535005838A5 /* ViewController.m in Sources */,
B5EC426518D94F6A001FE164 /* SGProgressView.m in Sources */,
45E7624617EC9535005838A5 /* AppDelegate.m in Sources */,
45E7626D17EC9593005838A5 /* UINavigationController+SGProgress.m in Sources */,
45E7624217EC9535005838A5 /* main.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// SGProgressView.h
// SGNavigationProgress
//
// Created by Ben on 19/03/2014.
// Copyright (c) 2014 Ben. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SGProgressView : UIView

/**
* The current progress shown by the receiver.
* The progress value ranges from 0 to 1. The default value is 0.
*/
@property (nonatomic, assign) float progress;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// SGProgressView.m
// SGNavigationProgress
//
// Created by Ben on 19/03/2014.
// Copyright (c) 2014 Ben. All rights reserved.
//

#import "SGProgressView.h"

@interface SGProgressView ()
@property (nonatomic, strong) UIView *progressBar;
@end

@implementation SGProgressView

- (void)setProgress:(float)progress {
_progress = (progress < 0) ? 0 :
(progress > 1) ? 1 :
progress;

CGRect slice, remainder;
CGRectDivide(self.bounds, &slice, &remainder, CGRectGetWidth(self.bounds) * _progress, CGRectMinXEdge);

if (!CGRectEqualToRect(self.progressBar.frame, slice)) {
self.progressBar.frame = slice;
}
}

#pragma mark - UIView

- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.frame = frame;
self.clipsToBounds = YES;
self.backgroundColor = [UIColor clearColor];
self.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
self.progressBar = [[UIView alloc] init];
self.progressBar.backgroundColor = self.tintColor;
self.progress = 0;
[self addSubview:self.progressBar];
}
return self;
}

- (void)setFrame:(CGRect)frame
{
// 0.5 pt doesn't work well with autoresizingMask.
frame.origin.y = ceilf(frame.origin.y);
frame.size.height = floorf(frame.size.height);
[super setFrame:frame];

__weak typeof(self)weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.progress = weakSelf.progress;
});
}

- (void)setTintColor:(UIColor *)tintColor
{
[super setTintColor:tintColor];
self.progressBar.backgroundColor = tintColor;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
- (void)showSGProgressWithDuration:(float)duration andTintColor:(UIColor *)tintColor;
- (void)showSGProgressWithDuration:(float)duration andTintColor:(UIColor *)tintColor andTitle:(NSString *)title;
- (void)showSGProgressWithMaskAndDuration:(float)duration;
- (void)showSGProgressWithMaskAndDuration:(float)duration andTitle:(NSString *) title;
- (void)showSGProgressWithMaskAndDuration:(float)duration andTitle:(NSString *)title;

- (void)finishSGProgress;
- (void)cancelSGProgress;

- (void)setSGProgressPercentage:(float)percentage;
- (void)setSGProgressPercentage:(float)percentage andTitle:(NSString *)title;
- (void)setSGProgressPercentage:(float)percentage andTintColor:(UIColor *)tintColor;
- (void)setSGProgressMaskWithPercentage:(float)percentage;
- (void)setSGProgressMaskWithPercentage:(float)percentage andTitle:(NSString *)title;


- (void)finishSGProgress;
- (void)cancelSGProgress;
@end
Loading

0 comments on commit 958974f

Please sign in to comment.