forked from ninjinkun/NJKWebViewProgress
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// NJKWebViewProgressView.h | ||
// iOS 7 Style WebView Progress Bar | ||
// | ||
// Created by Satoshi Aasano on 11/16/13. | ||
// Copyright (c) 2013 Satoshi Asano. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface NJKWebViewProgressView : UIView | ||
@property (nonatomic) float progress; | ||
|
||
@property (nonatomic) UIView *progressBarView; | ||
@property (nonatomic) NSTimeInterval barAnimationDuration; // default 0.1 | ||
@property (nonatomic) NSTimeInterval fadeAnimationDuration; // default 0.27 | ||
@property (nonatomic) NSTimeInterval fadeOutDelay; // default 0.1 | ||
|
||
- (void)setProgress:(float)progress animated:(BOOL)animated; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// NJKWebViewProgressView.m | ||
// | ||
// Created by Satoshi Aasanoon 11/16/13. | ||
// Copyright (c) 2013 Satoshi Asano. All rights reserved. | ||
// | ||
|
||
#import "NJKWebViewProgressView.h" | ||
|
||
@implementation NJKWebViewProgressView | ||
|
||
- (id)initWithFrame:(CGRect)frame | ||
{ | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
self.userInteractionEnabled = NO; | ||
self.autoresizingMask = UIViewAutoresizingFlexibleWidth; | ||
_progressBarView = [[UIView alloc] initWithFrame:self.bounds]; | ||
_progressBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth; | ||
_progressBarView.backgroundColor = [UIColor colorWithRed:22.f / 255.f green:126.f / 255.f blue:251.f / 255.f alpha:1.0]; // iOS7 Safari bar color | ||
[self addSubview:_progressBarView]; | ||
|
||
_barAnimationDuration = 0.27f; | ||
_fadeAnimationDuration = 0.27f; | ||
_fadeOutDelay = 0.1f; | ||
} | ||
return self; | ||
} | ||
|
||
-(void)setProgress:(float)progress | ||
{ | ||
[self setProgress:progress animated:NO]; | ||
} | ||
|
||
- (void)setProgress:(float)progress animated:(BOOL)animated | ||
{ | ||
BOOL isGrowing = progress > 0.0; | ||
[UIView animateWithDuration:(isGrowing && animated) ? _barAnimationDuration : 0.0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ | ||
CGRect frame = _progressBarView.frame; | ||
frame.size.width = progress * self.bounds.size.width; | ||
_progressBarView.frame = frame; | ||
} completion:nil]; | ||
|
||
if (progress >= 1.0) { | ||
[UIView animateWithDuration:animated ? _fadeAnimationDuration : 0.0 delay:_fadeOutDelay options:UIViewAnimationOptionCurveEaseInOut animations:^{ | ||
_progressBarView.alpha = 0.0; | ||
} completion:^(BOOL completed){ | ||
CGRect frame = _progressBarView.frame; | ||
frame.size.width = 0; | ||
_progressBarView.frame = frame; | ||
}]; | ||
} | ||
else { | ||
[UIView animateWithDuration:animated ? _fadeAnimationDuration : 0.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ | ||
_progressBarView.alpha = 1.0; | ||
} completion:nil]; | ||
} | ||
} | ||
|
||
@end |