Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Various Enhancements. Seemingly bug-free. Made Clip view used a flipp…

…ed context.
  • Loading branch information...
commit ef88761efcece820b1dedf0dc7aa97486dc95789 1 parent 5625711
@alexzielenski authored
View
1  ScrollToRefresh/src/EQSTRClipView.h
@@ -29,4 +29,5 @@
}
- (BOOL)isRefreshing;
- (NSView*)headerView;
+- (CGFloat)minimumScroll;
@end
View
22 ScrollToRefresh/src/EQSTRClipView.m
@@ -27,23 +27,25 @@
#import "EQSTRScrollView.h"
@implementation EQSTRClipView
-- (NSPoint)constrainScrollPoint:(NSPoint)proposedNewOrigin { // this method determines the "elastic" of the scroll view or how high it can scroll without resistence.
+- (NSPoint)constrainScrollPoint:(NSPoint)proposedNewOrigin { // this method determines the "elastic" of the scroll view or how high it can scroll without resistence.
NSPoint constrained = [super constrainScrollPoint:proposedNewOrigin];
- CGFloat scrollValue = proposedNewOrigin.y+self.documentVisibleRect.size.height; // this is the y value where the top of the document view is
-
+ CGFloat scrollValue = proposedNewOrigin.y; // this is the y value where the top of the document view is
+ BOOL over = scrollValue<=self.minimumScroll;
if (self.isRefreshing) { // if we are refreshing
- if (scrollValue>=self.headerView.frame.origin.y) { // and if we are scrolled past the refresh view
- if (scrollValue>=self.headerView.frame.origin.y+self.headerView.frame.size.height) // and if we are scrolled above the refresh view
- proposedNewOrigin.y = constrained.y+self.headerView.frame.size.height; // constrain us to the refresh view
- return NSMakePoint(constrained.x, proposedNewOrigin.y);
- }
+ if (over) // and if we are scrolled above the refresh view
+ constrained.y = 0-self.headerView.frame.size.height; // constrain us to the refresh view
+ return NSMakePoint(constrained.x, constrained.y);
}
return constrained;
}
+- (BOOL)isFlipped {
+ return YES;
+}
- (NSRect)documentRect { //this is to make scrolling feel more normal so that the spinner is within the scrolled area
NSRect sup = [super documentRect];
if (self.isRefreshing) {
sup.size.height+=self.headerView.frame.size.height;
+ sup.origin.y-=self.headerView.frame.size.height;
}
return sup;
}
@@ -53,7 +55,7 @@ - (BOOL)isRefreshing {
- (NSView*)headerView {
return [(EQSTRScrollView*)self.superview refreshHeader];
}
-- (BOOL)isFlipped {
- return NO;
+- (CGFloat)minimumScroll {
+ return [(EQSTRScrollView*)self.superview minimumScroll];
}
@end
View
5 ScrollToRefresh/src/EQSTRScrollView.h
@@ -40,11 +40,16 @@
@property (assign) SEL selector;
@property (readonly) BOOL isRefreshing;
+
@property (readonly) NSView *refreshHeader;
+@property (readonly) YRKSpinningProgressIndicator *refreshSpinner;
+@property (readonly) NSView *refreshArrow;
- (void)startLoading;
- (void)stopLoading;
- (BOOL)overRefreshView;
- (void)createHeaderView;
- (void)viewBoundsChanged:(NSNotification*)note;
+
+- (CGFloat)minimumScroll;
@end
View
41 ScrollToRefresh/src/EQSTRScrollView.m
@@ -31,19 +31,13 @@
// code modeled from https://github.com/leah/PullToRefresh/blob/master/Classes/PullRefreshTableViewController.m
@implementation EQSTRScrollView
-@synthesize isRefreshing, refreshHeader, target, selector;
-- (void)dealloc {
- [refreshHeader release];
- [refreshArrow release];
- [refreshSpinner release];
- [super dealloc];
-}
+@synthesize isRefreshing, refreshHeader, target, selector, refreshSpinner, refreshArrow;
- (void)viewDidMoveToWindow {
[self createHeaderView];
}
- (void)createHeaderView {
// delete old stuff if any
- if (refreshHeader) {
+ if (refreshHeader) {
[refreshHeader removeFromSuperview];
[refreshHeader release];
refreshHeader = nil;
@@ -60,6 +54,7 @@ - (void)createHeaderView {
clipView.drawsBackground=NO;
self.contentView=clipView;
+ [clipView release];
[self.contentView setPostsFrameChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -70,7 +65,7 @@ - (void)createHeaderView {
// add header view to clipview
NSRect contentRect = [self.contentView.documentView frame];
refreshHeader = [[NSView alloc] initWithFrame:NSMakeRect(0,
- contentRect.origin.y+contentRect.size.height,
+ 0-REFRESH_HEADER_HEIGHT, //contentRect.origin.y+contentRect.size.height,
contentRect.size.width,
REFRESH_HEADER_HEIGHT)];
@@ -96,25 +91,22 @@ - (void)createHeaderView {
refreshSpinner.drawsBackground=NO;
refreshSpinner.backgroundColor=[NSColor clearColor];
refreshSpinner.indeterminate=YES;
-
+ refreshSpinner.color=[NSColor colorWithDeviceRed:0.4171 green:0.4759 blue:0.5247 alpha:1.0000];
// set autoresizing masks
refreshSpinner.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin; // center
refreshArrow.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin; // center
- refreshHeader.autoresizingMask = NSViewWidthSizable | NSViewMinXMargin | NSViewMinYMargin | NSViewMaxXMargin; // stretch
+ refreshHeader.autoresizingMask = NSViewWidthSizable | NSViewMinXMargin | NSViewMaxXMargin; // stretch
[refreshHeader addSubview:refreshArrow];
[refreshHeader addSubview:refreshSpinner];
[self.contentView addSubview:refreshHeader];
- [clipView release];
-
-// if ([self.contentView.documentView respondsToSelector:@selector(scrollToBeginningOfDocument:)])
-// [self.contentView.documentView scrollToBeginningOfDocument:self];
+ [refreshArrow release];
+ [refreshSpinner release];
- [self.contentView scrollToPoint:NSMakePoint(contentRect.origin.x, contentRect.origin.y+contentRect.size.height-self.contentView.documentVisibleRect.size.height)];
+ [self.contentView scrollToPoint:NSMakePoint(contentRect.origin.x, 0)];
[self reflectScrolledClipView:self.contentView];
-
}
- (void)scrollWheel:(NSEvent *)event {
if (event.phase==NSEventPhaseEnded) {
@@ -125,9 +117,9 @@ - (void)scrollWheel:(NSEvent *)event {
[super scrollWheel:event];
}
- (void)viewBoundsChanged:(NSNotification*)note {
- BOOL start = [self overRefreshView];
if (isRefreshing)
return;
+ BOOL start = [self overRefreshView];
if (start) {
// point arrow up
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
@@ -143,10 +135,10 @@ - (BOOL)overRefreshView {
NSClipView *clipView = self.contentView;
NSRect bounds = clipView.bounds;
- CGFloat scrollValue = bounds.origin.y+bounds.size.height;
- CGFloat minimumScroll = refreshHeader.frame.origin.y+refreshHeader.frame.size.height;
+ CGFloat scrollValue = bounds.origin.y;
+ CGFloat minimumScroll = self.minimumScroll;
- return (scrollValue>=minimumScroll);
+ return (scrollValue<=minimumScroll);
}
- (void)startLoading {
[self willChangeValueForKey:@"isRefreshing"];
@@ -156,7 +148,7 @@ - (void)startLoading {
refreshArrow.hidden = YES;
[refreshSpinner startAnimation:self];
- if (self.target)
+ if (self.target&&[self.target respondsToSelector:self.selector])
[self.target performSelectorOnMainThread:self.selector
withObject:self
waitUntilDone:YES];
@@ -175,10 +167,13 @@ - (void)stopLoading {
CGEventRef cgEvent = CGEventCreateScrollWheelEvent(NULL,
kCGScrollEventUnitLine,
2,
- -1,
+ 1,
0);
NSEvent *scrollEvent = [NSEvent eventWithCGEvent:cgEvent];
[self scrollWheel:scrollEvent];
CFRelease(cgEvent);
}
+- (CGFloat)minimumScroll {
+ return 0-refreshHeader.frame.size.height;
+}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.