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

I have modify some #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions WKVerticalScrollBar/WKVerticalScrollBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ - (id)initWithFrame:(CGRect)frame
[handle setAnchorPoint:CGPointMake(1.0f, 0.0f)];
[handle setFrame:CGRectMake(0, 0, _handleWidth, 0)];
[handle setBackgroundColor:[normalColor CGColor]];

handle.cornerRadius = _handleWidth/2;

[[self layer] addSublayer:handle];
}
return self;
Expand Down Expand Up @@ -168,12 +171,17 @@ - (void)growHandle

[handle setBounds:CGRectMake(0, 0, _handleHighlightWidth, [handle bounds].size.height)];
[handle setBackgroundColor:[selectedColor CGColor]];
handle.cornerRadius = _handleHighlightWidth/2;

[CATransaction commit];

[UIView animateWithDuration:0.3f animations:^{
[_handleAccessoryView setAlpha:1.0f];
}];
[UIView transitionWithView:self
duration:0.3
options:UIViewAnimationCurveLinear
animations:^{
[_handleAccessoryView setAlpha:1.0f];
} completion:^(BOOL finished) {
}];
}

- (void)shrinkHandle
Expand All @@ -183,12 +191,19 @@ - (void)shrinkHandle

[handle setBounds:CGRectMake(0, 0, _handleWidth, [handle bounds].size.height)];
[handle setBackgroundColor:[normalColor CGColor]];
handle.cornerRadius = _handleWidth/2;

[CATransaction commit];

[UIView animateWithDuration:0.3f animations:^{
[_handleAccessoryView setAlpha:0.0f];
}];

[UIView transitionWithView:self
duration:0.3
options:UIViewAnimationCurveLinear
animations:^{
[_handleAccessoryView setAlpha:0.0f];
} completion:^(BOOL finished) {

}];
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
Expand All @@ -210,14 +225,15 @@ - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
{

CGPoint point = [touch locationInView:self];

CGSize contentSize = [_scrollView contentSize];
CGPoint contentOffset = [_scrollView contentOffset];
CGFloat frameHeight = [_scrollView frame].size.height;
CGFloat deltaY = ((point.y - lastTouchPoint.y) / [self bounds].size.height)
* [_scrollView contentSize].height;
CGFloat deltaY = ((point.y - lastTouchPoint.y) / (frameHeight - handle.bounds.size.height))
* contentSize.height;

[_scrollView setContentOffset:CGPointMake(contentOffset.x, CLAMP(contentOffset.y + deltaY,
0, contentSize.height - frameHeight))
Expand Down Expand Up @@ -248,4 +264,12 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
[self setNeedsLayout];
}

#pragma mark - setters

- (void)setHandleWidth:(CGFloat)handleWidth
{
_handleWidth = handleWidth;
handle.cornerRadius = _handleWidth/2;
}

@end