Skip to content

Commit

Permalink
Fixed animation glitches.
Browse files Browse the repository at this point in the history
  • Loading branch information
avaidyam committed Oct 19, 2012
1 parent 9bb5cce commit 935c46e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 4 additions & 0 deletions lib/UIKit/TUIScrollView+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

+ (BOOL)requiresElasticSrolling;

- (void)_updateScrollers;
- (void)_updateScrollersAnimated:(BOOL)animated;

@end

@interface TUIScroller ()

- (CGFloat)updatedScrollerWidth;
- (CGFloat)updatedScrollerCornerRadius;

@end
27 changes: 16 additions & 11 deletions lib/UIKit/TUIScroller.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ @interface TUIScroller () {
@property (nonatomic, assign) CGPoint mouseDown;
@property (nonatomic, assign) CGRect knobStartFrame;

@property (nonatomic, assign, getter = isTrackShown) BOOL trackShown;
@property (nonatomic, readonly, getter = isVertical) BOOL vertical;

- (void)_hideKnob;
Expand Down Expand Up @@ -148,6 +149,7 @@ - (void)_hideKnob {

self.hideKnobTimer = nil;
self.knobHidden = YES;
self.trackShown = NO;
[self _updateKnobAlphaWithSpeed:TUIScrollerStateChangeSpeed];
}

Expand All @@ -156,7 +158,9 @@ - (BOOL)isVertical {
}

- (BOOL)isExpanded {
return (_scrollerFlags.hover || _scrollerFlags.active) && [TUIScrollView requiresExpandingScrollers];
if(![TUIScrollView requiresExpandingScrollers])
return NO;
else return (_scrollerFlags.hover || (_scrollerFlags.active && self.knobHidden) || self.trackShown);
}

- (BOOL)isFlashing {
Expand All @@ -167,6 +171,10 @@ - (CGFloat)updatedScrollerWidth {
return self.expanded ? TUIScrollerExpandedWidth : TUIScrollerDefaultWidth;
}

- (CGFloat)updatedScrollerCornerRadius {
return self.expanded ? TUIScrollerExpandedCornerRadius : TUIScrollerDefaultCornerRadius;
}

- (void)layoutSubviews {
[self _updateKnob];
}
Expand All @@ -184,20 +192,15 @@ - (void)_updateKnob {
frame = CGRectIntegral(CGRectInset(frame, 4, 2));
}

[TUIView setAnimationsEnabled:NO block:^{
[self _refreshKnobTimer];
self.knob.frame = frame;
}];

[TUIView animateWithDuration:TUIScrollerStateChangeSpeed animations:^{
self.knob.layer.cornerRadius = self.expanded ? TUIScrollerExpandedCornerRadius : TUIScrollerDefaultCornerRadius;
}];
[self _refreshKnobTimer];
self.knob.frame = frame;
self.knob.layer.cornerRadius = self.updatedScrollerCornerRadius;
}

- (void)drawRect:(CGRect)rect {
if(!self.expanded || ![TUIScrollView requiresExpandingScrollers]) {
if(!self.expanded || ![TUIScrollView requiresExpandingScrollers])
return;
}
else self.trackShown = YES;

// TUIScrollViewIndicatorStyleLight draws a dark track underneath,
// but the other indicator styles draw a light track.
Expand Down Expand Up @@ -267,6 +270,7 @@ - (void)setScrollIndicatorStyle:(TUIScrollViewIndicatorStyle)style {
- (void)mouseEntered:(NSEvent *)event {
_scrollerFlags.hover = 1;
[self _updateKnobAlphaWithSpeed:TUIScrollerRefreshSpeed];
[self.scrollView _updateScrollersAnimated:YES];

// Propogate mouse events.
[super mouseEntered:event];
Expand All @@ -275,6 +279,7 @@ - (void)mouseEntered:(NSEvent *)event {
- (void)mouseExited:(NSEvent *)event {
_scrollerFlags.hover = 0;
[self _updateKnobAlphaWithSpeed:TUIScrollerStateChangeSpeed];
[self.scrollView _updateScrollersAnimated:YES];

// Propogate mouse events.
[super mouseExited:event];
Expand Down

0 comments on commit 935c46e

Please sign in to comment.