diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..2da6ff7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Mac OS X +*.DS_Store +*.psd + +# Xcode +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 +*.xcuserstate +project.xcworkspace/ +xcuserdata/ + +# Generated files +build/ +*.[oa] +*.pyc + +# Backup files +*~.nib \ No newline at end of file diff --git a/Demo/SVPullToRefreshDemo.xcodeproj/project.pbxproj b/Demo/SVPullToRefreshDemo.xcodeproj/project.pbxproj new file mode 100644 index 00000000..6baa4184 --- /dev/null +++ b/Demo/SVPullToRefreshDemo.xcodeproj/project.pbxproj @@ -0,0 +1,312 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 22E0D9191545EE5B00BB6BB5 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22E0D9181545EE5B00BB6BB5 /* UIKit.framework */; }; + 22E0D91B1545EE5B00BB6BB5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22E0D91A1545EE5B00BB6BB5 /* Foundation.framework */; }; + 22E0D91D1545EE5B00BB6BB5 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22E0D91C1545EE5B00BB6BB5 /* CoreGraphics.framework */; }; + 22E0D9231545EE5B00BB6BB5 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 22E0D9211545EE5B00BB6BB5 /* InfoPlist.strings */; }; + 22E0D9251545EE5B00BB6BB5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E0D9241545EE5B00BB6BB5 /* main.m */; }; + 22E0D9291545EE5B00BB6BB5 /* SVAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E0D9281545EE5B00BB6BB5 /* SVAppDelegate.m */; }; + 22E0D92C1545EE5B00BB6BB5 /* SVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E0D92B1545EE5B00BB6BB5 /* SVViewController.m */; }; + 22E0D92F1545EE5B00BB6BB5 /* SVViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22E0D92D1545EE5B00BB6BB5 /* SVViewController.xib */; }; + 22E0D93D1545EE7600BB6BB5 /* SVPullToRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E0D93B1545EE7600BB6BB5 /* SVPullToRefresh.m */; }; + 22E0D93E1545EE7600BB6BB5 /* SVPullToRefresh.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 22E0D93C1545EE7600BB6BB5 /* SVPullToRefresh.bundle */; }; + 22E0D9411545EE9000BB6BB5 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22E0D9401545EE9000BB6BB5 /* QuartzCore.framework */; }; + 22E0D94B1545F63300BB6BB5 /* README.textile in Resources */ = {isa = PBXBuildFile; fileRef = 22E0D94A1545F63300BB6BB5 /* README.textile */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 22E0D9141545EE5B00BB6BB5 /* SVPullToRefreshDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SVPullToRefreshDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 22E0D9181545EE5B00BB6BB5 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 22E0D91A1545EE5B00BB6BB5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 22E0D91C1545EE5B00BB6BB5 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + 22E0D9201545EE5B00BB6BB5 /* SVPullToRefreshDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SVPullToRefreshDemo-Info.plist"; sourceTree = ""; }; + 22E0D9221545EE5B00BB6BB5 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 22E0D9241545EE5B00BB6BB5 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 22E0D9261545EE5B00BB6BB5 /* SVPullToRefreshDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SVPullToRefreshDemo-Prefix.pch"; sourceTree = ""; }; + 22E0D9271545EE5B00BB6BB5 /* SVAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVAppDelegate.h; sourceTree = ""; }; + 22E0D9281545EE5B00BB6BB5 /* SVAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVAppDelegate.m; sourceTree = ""; }; + 22E0D92A1545EE5B00BB6BB5 /* SVViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVViewController.h; sourceTree = ""; }; + 22E0D92B1545EE5B00BB6BB5 /* SVViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVViewController.m; sourceTree = ""; }; + 22E0D92E1545EE5B00BB6BB5 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/SVViewController.xib; sourceTree = ""; }; + 22E0D93A1545EE7600BB6BB5 /* SVPullToRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVPullToRefresh.h; sourceTree = ""; }; + 22E0D93B1545EE7600BB6BB5 /* SVPullToRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVPullToRefresh.m; sourceTree = ""; }; + 22E0D93C1545EE7600BB6BB5 /* SVPullToRefresh.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = SVPullToRefresh.bundle; sourceTree = ""; }; + 22E0D9401545EE9000BB6BB5 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 22E0D94A1545F63300BB6BB5 /* README.textile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.textile; path = ../README.textile; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 22E0D9111545EE5B00BB6BB5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 22E0D9411545EE9000BB6BB5 /* QuartzCore.framework in Frameworks */, + 22E0D9191545EE5B00BB6BB5 /* UIKit.framework in Frameworks */, + 22E0D91B1545EE5B00BB6BB5 /* Foundation.framework in Frameworks */, + 22E0D91D1545EE5B00BB6BB5 /* CoreGraphics.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 22E0D9091545EE5B00BB6BB5 = { + isa = PBXGroup; + children = ( + 22E0D94A1545F63300BB6BB5 /* README.textile */, + 22E0D91E1545EE5B00BB6BB5 /* Demo */, + 22E0D9391545EE7600BB6BB5 /* SVPullToRefresh */, + 22E0D9171545EE5B00BB6BB5 /* Frameworks */, + 22E0D9151545EE5B00BB6BB5 /* Products */, + ); + sourceTree = ""; + }; + 22E0D9151545EE5B00BB6BB5 /* Products */ = { + isa = PBXGroup; + children = ( + 22E0D9141545EE5B00BB6BB5 /* SVPullToRefreshDemo.app */, + ); + name = Products; + sourceTree = ""; + }; + 22E0D9171545EE5B00BB6BB5 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 22E0D9401545EE9000BB6BB5 /* QuartzCore.framework */, + 22E0D9181545EE5B00BB6BB5 /* UIKit.framework */, + 22E0D91A1545EE5B00BB6BB5 /* Foundation.framework */, + 22E0D91C1545EE5B00BB6BB5 /* CoreGraphics.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 22E0D91E1545EE5B00BB6BB5 /* Demo */ = { + isa = PBXGroup; + children = ( + 22E0D9271545EE5B00BB6BB5 /* SVAppDelegate.h */, + 22E0D9281545EE5B00BB6BB5 /* SVAppDelegate.m */, + 22E0D92A1545EE5B00BB6BB5 /* SVViewController.h */, + 22E0D92B1545EE5B00BB6BB5 /* SVViewController.m */, + 22E0D92D1545EE5B00BB6BB5 /* SVViewController.xib */, + 22E0D91F1545EE5B00BB6BB5 /* Supporting Files */, + ); + name = Demo; + path = SVPullToRefreshDemo; + sourceTree = ""; + }; + 22E0D91F1545EE5B00BB6BB5 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 22E0D9201545EE5B00BB6BB5 /* SVPullToRefreshDemo-Info.plist */, + 22E0D9211545EE5B00BB6BB5 /* InfoPlist.strings */, + 22E0D9241545EE5B00BB6BB5 /* main.m */, + 22E0D9261545EE5B00BB6BB5 /* SVPullToRefreshDemo-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 22E0D9391545EE7600BB6BB5 /* SVPullToRefresh */ = { + isa = PBXGroup; + children = ( + 22E0D93A1545EE7600BB6BB5 /* SVPullToRefresh.h */, + 22E0D93B1545EE7600BB6BB5 /* SVPullToRefresh.m */, + 22E0D93C1545EE7600BB6BB5 /* SVPullToRefresh.bundle */, + ); + name = SVPullToRefresh; + path = ../SVPullToRefresh; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 22E0D9131545EE5B00BB6BB5 /* SVPullToRefreshDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 22E0D9321545EE5B00BB6BB5 /* Build configuration list for PBXNativeTarget "SVPullToRefreshDemo" */; + buildPhases = ( + 22E0D9101545EE5B00BB6BB5 /* Sources */, + 22E0D9111545EE5B00BB6BB5 /* Frameworks */, + 22E0D9121545EE5B00BB6BB5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SVPullToRefreshDemo; + productName = SVPullToRefreshDemo; + productReference = 22E0D9141545EE5B00BB6BB5 /* SVPullToRefreshDemo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 22E0D90B1545EE5B00BB6BB5 /* Project object */ = { + isa = PBXProject; + attributes = { + CLASSPREFIX = SV; + LastUpgradeCheck = 0430; + ORGANIZATIONNAME = Home; + }; + buildConfigurationList = 22E0D90E1545EE5B00BB6BB5 /* Build configuration list for PBXProject "SVPullToRefreshDemo" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 22E0D9091545EE5B00BB6BB5; + productRefGroup = 22E0D9151545EE5B00BB6BB5 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 22E0D9131545EE5B00BB6BB5 /* SVPullToRefreshDemo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 22E0D9121545EE5B00BB6BB5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 22E0D9231545EE5B00BB6BB5 /* InfoPlist.strings in Resources */, + 22E0D92F1545EE5B00BB6BB5 /* SVViewController.xib in Resources */, + 22E0D93E1545EE7600BB6BB5 /* SVPullToRefresh.bundle in Resources */, + 22E0D94B1545F63300BB6BB5 /* README.textile in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 22E0D9101545EE5B00BB6BB5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 22E0D9251545EE5B00BB6BB5 /* main.m in Sources */, + 22E0D9291545EE5B00BB6BB5 /* SVAppDelegate.m in Sources */, + 22E0D92C1545EE5B00BB6BB5 /* SVViewController.m in Sources */, + 22E0D93D1545EE7600BB6BB5 /* SVPullToRefresh.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 22E0D9211545EE5B00BB6BB5 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 22E0D9221545EE5B00BB6BB5 /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 22E0D92D1545EE5B00BB6BB5 /* SVViewController.xib */ = { + isa = PBXVariantGroup; + children = ( + 22E0D92E1545EE5B00BB6BB5 /* en */, + ); + name = SVViewController.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 22E0D9301545EE5B00BB6BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 22E0D9311545EE5B00BB6BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 22E0D9331545EE5B00BB6BB5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "SVPullToRefreshDemo/SVPullToRefreshDemo-Prefix.pch"; + INFOPLIST_FILE = "SVPullToRefreshDemo/SVPullToRefreshDemo-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + 22E0D9341545EE5B00BB6BB5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "SVPullToRefreshDemo/SVPullToRefreshDemo-Prefix.pch"; + INFOPLIST_FILE = "SVPullToRefreshDemo/SVPullToRefreshDemo-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 22E0D90E1545EE5B00BB6BB5 /* Build configuration list for PBXProject "SVPullToRefreshDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 22E0D9301545EE5B00BB6BB5 /* Debug */, + 22E0D9311545EE5B00BB6BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 22E0D9321545EE5B00BB6BB5 /* Build configuration list for PBXNativeTarget "SVPullToRefreshDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 22E0D9331545EE5B00BB6BB5 /* Debug */, + 22E0D9341545EE5B00BB6BB5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 22E0D90B1545EE5B00BB6BB5 /* Project object */; +} diff --git a/Demo/SVPullToRefreshDemo/SVAppDelegate.h b/Demo/SVPullToRefreshDemo/SVAppDelegate.h new file mode 100644 index 00000000..9f2047ea --- /dev/null +++ b/Demo/SVPullToRefreshDemo/SVAppDelegate.h @@ -0,0 +1,19 @@ +// +// SVAppDelegate.h +// SVPullToRefreshDemo +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// + +#import + +@class SVViewController; + +@interface SVAppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@property (strong, nonatomic) SVViewController *viewController; + +@end diff --git a/Demo/SVPullToRefreshDemo/SVAppDelegate.m b/Demo/SVPullToRefreshDemo/SVAppDelegate.m new file mode 100644 index 00000000..d9ea5f31 --- /dev/null +++ b/Demo/SVPullToRefreshDemo/SVAppDelegate.m @@ -0,0 +1,55 @@ +// +// SVAppDelegate.m +// SVPullToRefreshDemo +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// + +#import "SVAppDelegate.h" + +#import "SVViewController.h" + +@implementation SVAppDelegate + +@synthesize window = _window; +@synthesize viewController = _viewController; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + // Override point for customization after application launch. + self.viewController = [[SVViewController alloc] initWithNibName:@"SVViewController" bundle:nil]; + self.window.rootViewController = self.viewController; + [self.window makeKeyAndVisible]; + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +@end diff --git a/Demo/SVPullToRefreshDemo/SVPullToRefreshDemo-Info.plist b/Demo/SVPullToRefreshDemo/SVPullToRefreshDemo-Info.plist new file mode 100644 index 00000000..7c2dbdbc --- /dev/null +++ b/Demo/SVPullToRefreshDemo/SVPullToRefreshDemo-Info.plist @@ -0,0 +1,38 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.samvermette.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Demo/SVPullToRefreshDemo/SVPullToRefreshDemo-Prefix.pch b/Demo/SVPullToRefreshDemo/SVPullToRefreshDemo-Prefix.pch new file mode 100644 index 00000000..8f4f4720 --- /dev/null +++ b/Demo/SVPullToRefreshDemo/SVPullToRefreshDemo-Prefix.pch @@ -0,0 +1,14 @@ +// +// Prefix header for all source files of the 'SVPullToRefreshDemo' target in the 'SVPullToRefreshDemo' project +// + +#import + +#ifndef __IPHONE_4_0 +#warning "This project uses features only available in iOS SDK 4.0 and later." +#endif + +#ifdef __OBJC__ + #import + #import +#endif diff --git a/Demo/SVPullToRefreshDemo/SVViewController.h b/Demo/SVPullToRefreshDemo/SVViewController.h new file mode 100644 index 00000000..bce6e360 --- /dev/null +++ b/Demo/SVPullToRefreshDemo/SVViewController.h @@ -0,0 +1,15 @@ +// +// SVViewController.h +// SVPullToRefreshDemo +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// + +#import + +@interface SVViewController : UIViewController + +@property (nonatomic, strong) IBOutlet UITableView *tableView; + +@end diff --git a/Demo/SVPullToRefreshDemo/SVViewController.m b/Demo/SVPullToRefreshDemo/SVViewController.m new file mode 100644 index 00000000..1a2028cc --- /dev/null +++ b/Demo/SVPullToRefreshDemo/SVViewController.m @@ -0,0 +1,57 @@ +// +// SVViewController.m +// SVPullToRefreshDemo +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 Home. All rights reserved. +// + +#import "SVViewController.h" +#import "SVPullToRefresh.h" + +@interface SVViewController () + +@end + +@implementation SVViewController + +@synthesize tableView; + +- (void)viewDidLoad { + [super viewDidLoad]; + [self.tableView addPullToRefreshWithActionHandler:^{ + NSLog(@"refresh dataSource"); + [tableView.pullToRefreshView performSelector:@selector(stopAnimating) withObject:nil afterDelay:2]; + }]; +} + +#pragma mark - +#pragma mark UITableViewDataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 10; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return 4; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + static NSString *identifier = @"Cell"; + + UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:identifier]; + + if (cell == nil) + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; + + // Configure the cell. + + return cell; +} + +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ + return [NSString stringWithFormat:@"Section %i", section]; +} + +@end diff --git a/Demo/SVPullToRefreshDemo/en.lproj/InfoPlist.strings b/Demo/SVPullToRefreshDemo/en.lproj/InfoPlist.strings new file mode 100644 index 00000000..477b28ff --- /dev/null +++ b/Demo/SVPullToRefreshDemo/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/Demo/SVPullToRefreshDemo/en.lproj/SVViewController.xib b/Demo/SVPullToRefreshDemo/en.lproj/SVViewController.xib new file mode 100644 index 00000000..361a3beb --- /dev/null +++ b/Demo/SVPullToRefreshDemo/en.lproj/SVViewController.xib @@ -0,0 +1,192 @@ + + + + 1296 + 11D50b + 2182 + 1138.32 + 568.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1179 + + + IBProxyObject + IBUIView + IBUITableView + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 274 + {320, 460} + + + _NS:9 + + 3 + MQA + + YES + IBCocoaTouchFramework + YES + 1 + 0 + YES + 44 + 22 + 22 + + + {{0, 20}, {320, 460}} + + + + + 3 + MC43NQA + + 2 + + + NO + + IBCocoaTouchFramework + + + + + + + view + + + + 7 + + + + tableView + + + + 12 + + + + dataSource + + + + 9 + + + + delegate + + + + 10 + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 6 + + + + + + + + 8 + + + + + + + SVViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 12 + + + + + SVViewController + UIViewController + + tableView + UITableView + + + tableView + + tableView + UITableView + + + + IBProjectSource + ./Classes/SVViewController.h + + + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + 1179 + + diff --git a/Demo/SVPullToRefreshDemo/main.m b/Demo/SVPullToRefreshDemo/main.m new file mode 100644 index 00000000..83477c4d --- /dev/null +++ b/Demo/SVPullToRefreshDemo/main.m @@ -0,0 +1,18 @@ +// +// main.m +// SVPullToRefreshDemo +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// + +#import + +#import "SVAppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([SVAppDelegate class])); + } +} diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..ce9f4aba --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright (C) 2012 Sam Vermette + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.textile b/README.textile new file mode 100644 index 00000000..95946a18 --- /dev/null +++ b/README.textile @@ -0,0 +1,43 @@ +h1. SVPullToRefresh + +SVPullToRefresh allow you to easily add pull-to-refresh functionality to any UIScrollView subclass. Instead of depending on delegates and/or subclassing UIViewController, SVPullToRefresh extends UIScrollView with: + +* a - (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler method +* a @pullToRefreshView@ property + +h2. Installation + +* Drag the @SVPullToRefresh/SVPullToRefresh@ folder into your project. +* Add the *QuartzCore* framework to your project. +* @#import "SVPullToRefresh.h"@ + +h2. Usage + +(see sample Xcode project in @/Demo@) + +Adding pull-to-refresh to a table view can be done with one single line of code: + +
+[tableView addPullToRefreshWithActionHandler:^{
+    // refresh data
+	// call [tableView.pullToRefreshView stopAnimating] when done
+}];
+
+ +h2. Customization + +The SVPullToRefresh view can be customized with the following properties: + +
+@property (nonatomic, strong) UIColor *arrowColor;
+@property (nonatomic, strong) UIColor *textColor;
+@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle;
+
+ +h2. Under the hood + +SVPullToRefresh extends UIScrollView by adding a new public method as well as a dynamic property (thanks @seb_morel!). It uses key-value observing to track the scrollView's contentOffset, which removes the need for the view to be linked to the UIScrollViewDelegate protocol. + +h2. Credits + +SVPullToRefresh is brought to you by "Sam Vermette":http://samvermette.com and "contributors to the project":https://github.com/samvermette/SVPullToRefresh/contributors. If you have feature suggestions or bug reports, feel free to help out by sending pull requests or by "creating new issues":https://github.com/samvermette/SVPullToRefresh/issues/new. If you're using SVPullToRefresh in your project, attribution would be nice. Big thanks to @seb_morel for his "Demistifying the Objective-C runtime":http://cocoaheadsmtl.s3.amazonaws.com/demistifying-runtime.pdf which permitted the high abstraction of this class. \ No newline at end of file diff --git a/SVPullToRefresh/SVPullToRefresh.bundle/arrow.png b/SVPullToRefresh/SVPullToRefresh.bundle/arrow.png new file mode 100644 index 00000000..d810426d Binary files /dev/null and b/SVPullToRefresh/SVPullToRefresh.bundle/arrow.png differ diff --git a/SVPullToRefresh/SVPullToRefresh.bundle/arrow@2x.png b/SVPullToRefresh/SVPullToRefresh.bundle/arrow@2x.png new file mode 100644 index 00000000..67317a49 Binary files /dev/null and b/SVPullToRefresh/SVPullToRefresh.bundle/arrow@2x.png differ diff --git a/SVPullToRefresh/SVPullToRefresh.h b/SVPullToRefresh/SVPullToRefresh.h new file mode 100644 index 00000000..02aba12b --- /dev/null +++ b/SVPullToRefresh/SVPullToRefresh.h @@ -0,0 +1,31 @@ +// +// SVPullToRefresh.h +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// +// https://github.com/samvermette/SVPullToRefresh +// + +#import + +@interface SVPullToRefresh : UIView + +@property (nonatomic, strong) UIColor *arrowColor; +@property (nonatomic, strong) UIColor *textColor; +@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle; + +- (void)stopAnimating; + +@end + + +// extends UIScrollView + +@interface UIScrollView (SVPullToRefresh) + +- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler; + +@property (nonatomic, strong) SVPullToRefresh *pullToRefreshView; + +@end \ No newline at end of file diff --git a/SVPullToRefresh/SVPullToRefresh.m b/SVPullToRefresh/SVPullToRefresh.m new file mode 100644 index 00000000..73d0d623 --- /dev/null +++ b/SVPullToRefresh/SVPullToRefresh.m @@ -0,0 +1,234 @@ +// +// SVPullToRefresh.m +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// +// https://github.com/samvermette/SVPullToRefresh +// + +#import +#import "SVPullToRefresh.h" + +enum { + SVPullToRefreshStateHidden = 1, + SVPullToRefreshStateVisible, + SVPullToRefreshStateTriggered, + SVPullToRefreshStateLoading +}; + +typedef NSUInteger SVPullToRefreshState; + + +@interface SVPullToRefresh () + +- (id)initWithScrollView:(UIScrollView*)scrollView; +- (void)rotateArrow:(float)degrees hide:(BOOL)hide; +- (void)setScrollViewContentInset:(UIEdgeInsets)contentInset; +- (void)scrollViewDidScroll:(CGPoint)contentOffset; + +@property (nonatomic, copy) void (^actionHandler)(void); +@property (nonatomic, readwrite) SVPullToRefreshState state; + +@property (nonatomic, strong) UIImageView *arrow; +@property (nonatomic, strong, readonly) UIImage *arrowImage; +@property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView; +@property (nonatomic, strong) UILabel *titleLabel; + +@property (nonatomic, strong) UIScrollView *scrollView; +@property (nonatomic, readwrite) UIEdgeInsets originalScrollViewContentInset; + +@end + + +@implementation SVPullToRefresh + +// public properties +@synthesize actionHandler, arrowColor, textColor, activityIndicatorViewStyle; + +@synthesize state; +@synthesize scrollView = _scrollView; +@synthesize arrow, arrowImage, activityIndicatorView, titleLabel, originalScrollViewContentInset; + +- (id)initWithScrollView:(UIScrollView *)scrollView { + self = [super initWithFrame:CGRectZero]; + self.scrollView = scrollView; + [_scrollView addSubview:self]; + + self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ceil(self.superview.bounds.size.width*0.21+44), 20, 150, 20)]; + titleLabel.text = NSLocalizedString(@"Pull to refresh...",); + titleLabel.font = [UIFont boldSystemFontOfSize:14]; + titleLabel.backgroundColor = [UIColor clearColor]; + [self addSubview:titleLabel]; + + // default styling values + self.arrowColor = [UIColor grayColor]; + self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; + self.titleLabel.textColor = [UIColor darkGrayColor]; + + [self addSubview:self.arrow]; + + [scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; + self.originalScrollViewContentInset = scrollView.contentInset; + + self.state = SVPullToRefreshStateHidden; + self.frame = CGRectMake(0, -60, scrollView.bounds.size.width, 60); + + return self; +} + + +#pragma mark - Getters + +- (UIImageView *)arrow { + if(!arrow) { + arrow = [[UIImageView alloc] initWithImage:self.arrowImage]; + arrow.frame = CGRectMake(ceil(self.superview.bounds.size.width*0.21), 6, 22, 48); + arrow.backgroundColor = [UIColor clearColor]; + } + return arrow; +} + +- (UIImage *)arrowImage { + CGRect rect = CGRectMake(0, 0, 22, 48); + UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); + + CGContextRef context = UIGraphicsGetCurrentContext(); + [[UIColor clearColor] set]; + CGContextFillRect(context, rect); + + [self.arrowColor set]; + CGContextTranslateCTM(context, 0, rect.size.height); + CGContextScaleCTM(context, 1.0, -1.0); + CGContextClipToMask(context, rect, [[UIImage imageNamed:@"SVPullToRefresh.bundle/arrow"] CGImage]); + CGContextFillRect(context, rect); + + UIImage *output = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return output; +} + +- (UIActivityIndicatorView *)activityIndicatorView { + if(!activityIndicatorView) { + activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; + activityIndicatorView.hidesWhenStopped = YES; + [self addSubview:activityIndicatorView]; + self.activityIndicatorView.center = self.arrow.center; + } + return activityIndicatorView; +} + +#pragma mark - Setters + +- (void)setArrowColor:(UIColor *)newArrowColor { + arrowColor = newArrowColor; + self.arrow.image = self.arrowImage; +} + +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)viewStyle { + self.activityIndicatorView.activityIndicatorViewStyle = viewStyle; +} + +- (void)setScrollViewContentInset:(UIEdgeInsets)contentInset { + [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + self.scrollView.contentInset = contentInset; + } completion:NULL]; +} + + +#pragma mark - + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if([keyPath isEqualToString:@"contentOffset"]) + [self scrollViewDidScroll:[[change valueForKey:NSKeyValueChangeNewKey] CGPointValue]]; +} + +- (void)scrollViewDidScroll:(CGPoint)contentOffset { + CGFloat scrollOffsetThreshold = self.frame.origin.y-self.originalScrollViewContentInset.top; + + if(!self.scrollView.isDragging && self.state == SVPullToRefreshStateTriggered) + self.state = SVPullToRefreshStateLoading; + else if(contentOffset.y > scrollOffsetThreshold && contentOffset.y < -self.originalScrollViewContentInset.top && self.scrollView.isDragging && self.state != SVPullToRefreshStateLoading) + self.state = SVPullToRefreshStateVisible; + else if(contentOffset.y < scrollOffsetThreshold && self.scrollView.isDragging && self.state == SVPullToRefreshStateVisible) + self.state = SVPullToRefreshStateTriggered; + else if(contentOffset.y >= -self.originalScrollViewContentInset.top && self.state != SVPullToRefreshStateHidden) + self.state = SVPullToRefreshStateHidden; +} + +- (void)stopAnimating { + self.state = SVPullToRefreshStateHidden; +} + +- (void)setState:(SVPullToRefreshState)newState { + state = newState; + + switch (newState) { + case SVPullToRefreshStateHidden: + titleLabel.text = NSLocalizedString(@"Pull to refresh...",); + [self.activityIndicatorView stopAnimating]; + [self setScrollViewContentInset:self.originalScrollViewContentInset]; + [self rotateArrow:0 hide:YES]; + break; + + case SVPullToRefreshStateVisible: + titleLabel.text = NSLocalizedString(@"Pull to refresh...",); + [self.activityIndicatorView stopAnimating]; + [self setScrollViewContentInset:self.originalScrollViewContentInset]; + [self rotateArrow:0 hide:NO]; + break; + + case SVPullToRefreshStateTriggered: + titleLabel.text = NSLocalizedString(@"Release to refresh...",); + [self rotateArrow:M_PI hide:NO]; + break; + + case SVPullToRefreshStateLoading: + titleLabel.text = NSLocalizedString(@"Loading...",); + [self.activityIndicatorView startAnimating]; + [self setScrollViewContentInset:UIEdgeInsetsMake(self.frame.origin.y*-1+self.originalScrollViewContentInset.top, 0, 0, 0)]; + [self rotateArrow:0 hide:YES]; + if(actionHandler) + actionHandler(); + break; + } +} + +- (void)rotateArrow:(float)degrees hide:(BOOL)hide { + [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + self.arrow.layer.transform = CATransform3DMakeRotation(degrees, 0, 0, 1); + self.arrow.layer.opacity = !hide; + } completion:NULL]; +} + +@end + + +#pragma mark - UIScrollView (SVPullToRefresh) +#import + +static char UIScrollViewPullToRefreshView; + +@implementation UIScrollView (SVPullToRefresh) + +@dynamic pullToRefreshView; + +- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler { + SVPullToRefresh *pullToRefreshView = [[SVPullToRefresh alloc] initWithScrollView:self]; + pullToRefreshView.actionHandler = actionHandler; + self.pullToRefreshView = pullToRefreshView; +} + +- (void)setPullToRefreshView:(SVPullToRefresh *)pullToRefreshView { + [self willChangeValueForKey:@"pullToRefreshView"]; + objc_setAssociatedObject(self, &UIScrollViewPullToRefreshView, + pullToRefreshView, + OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self didChangeValueForKey:@"pullToRefreshView"]; +} + +- (SVPullToRefresh *)pullToRefreshView { + return objc_getAssociatedObject(self, &UIScrollViewPullToRefreshView); +} + +@end