Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 50caa9472c563321cb4792885290e2c03063b4dc @danielamitay committed Feb 14, 2012
Showing with 1,971 additions and 0 deletions.
  1. BIN .DS_Store
  2. +21 −0 DAAutoScroll/DAAutoScrollView.h
  3. +110 −0 DAAutoScroll/DAAutoScrollView.m
  4. +21 −0 DAAutoScroll/DAAutoTableView.h
  5. +110 −0 DAAutoScroll/DAAutoTableView.m
  6. +21 −0 DAAutoScroll/DAAutoTextView.h
  7. +110 −0 DAAutoScroll/DAAutoTextView.m
  8. +331 −0 DAAutoScrollExample/DAAutoScrollExample.xcodeproj/project.pbxproj
  9. +7 −0 DAAutoScrollExample/DAAutoScrollExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  10. BIN ....xcodeproj/project.xcworkspace/xcuserdata/danielamitay.xcuserdatad/UserInterfaceState.xcuserstate
  11. +84 −0 ...crollExample.xcodeproj/xcuserdata/danielamitay.xcuserdatad/xcschemes/DAAutoScrollExample.xcscheme
  12. +22 −0 ...utoScrollExample.xcodeproj/xcuserdata/danielamitay.xcuserdatad/xcschemes/xcschememanagement.plist
  13. +17 −0 DAAutoScrollExample/DAAutoScrollExample/AppDelegate.h
  14. +69 −0 DAAutoScrollExample/DAAutoScrollExample/AppDelegate.m
  15. +40 −0 DAAutoScrollExample/DAAutoScrollExample/DAAutoScrollExample-Info.plist
  16. +14 −0 DAAutoScrollExample/DAAutoScrollExample/DAAutoScrollExample-Prefix.pch
  17. +13 −0 DAAutoScrollExample/DAAutoScrollExample/MasterViewController.h
  18. +131 −0 DAAutoScrollExample/DAAutoScrollExample/MasterViewController.m
  19. +13 −0 DAAutoScrollExample/DAAutoScrollExample/TableViewController.h
  20. +163 −0 DAAutoScrollExample/DAAutoScrollExample/TableViewController.m
  21. +154 −0 DAAutoScrollExample/DAAutoScrollExample/TableViewController.xib
  22. +17 −0 DAAutoScrollExample/DAAutoScrollExample/TextViewController.h
  23. +56 −0 DAAutoScrollExample/DAAutoScrollExample/TextViewController.m
  24. +194 −0 DAAutoScrollExample/DAAutoScrollExample/TextViewController.xib
  25. +2 −0 DAAutoScrollExample/DAAutoScrollExample/en.lproj/InfoPlist.strings
  26. +139 −0 DAAutoScrollExample/DAAutoScrollExample/en.lproj/MasterViewController.xib
  27. +18 −0 DAAutoScrollExample/DAAutoScrollExample/main.m
  28. +23 −0 LICENSE.md
  29. +71 −0 README.md
BIN .DS_Store
Binary file not shown.
@@ -0,0 +1,21 @@
+//
+// DAAutoScrollView.h
+// DAAutoScroll
+//
+// Created by Daniel Amitay on 2/13/12.
+// Copyright (c) 2012 Daniel Amitay. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface DAAutoScrollView : UIScrollView
+{
+ NSTimer *_scrollTimer;
+}
+
+@property (nonatomic) CGFloat pointsPerSecond;
+
+- (void)startScrolling;
+- (void)stopScrolling;
+
+@end
@@ -0,0 +1,110 @@
+//
+// DAAutoScrollView.m
+// DAAutoScroll
+//
+// Created by Daniel Amitay on 2/13/12.
+// Copyright (c) 2012 Daniel Amitay. All rights reserved.
+//
+
+#import "DAAutoScrollView.h"
+
+@implementation DAAutoScrollView
+
+@synthesize pointsPerSecond = _pointsPerSecond;
+
+- (void)willMoveToWindow:(UIWindow *)newWindow
+{
+ [super willMoveToWindow:newWindow];
+ if(newWindow)
+ {
+ [self.panGestureRecognizer addTarget:self action:@selector(gestureDidChange:)];
+ [self.pinchGestureRecognizer addTarget:self action:@selector(gestureDidChange:)];
+ }
+ else
+ {
+ [self stopScrolling];
+ [self.panGestureRecognizer removeTarget:self action:@selector(gestureDidChange:)];
+ [self.pinchGestureRecognizer removeTarget:self action:@selector(gestureDidChange:)];
+ }
+}
+
+#pragma mark - Touch methods
+
+- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
+{
+ [self stopScrolling];
+ return [super touchesShouldBegin:touches withEvent:event inContentView:view];
+}
+
+- (void)gestureDidChange:(UIGestureRecognizer *)gesture
+{
+ switch (gesture.state)
+ {
+ case UIGestureRecognizerStateBegan:
+ {
+ [self stopScrolling];
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+- (BOOL)becomeFirstResponder
+{
+ [self stopScrolling];
+ return [super becomeFirstResponder];
+}
+
+#pragma mark - Property methods
+
+- (CGFloat)pointsPerSecond
+{
+ if (!_pointsPerSecond)
+ {
+ _pointsPerSecond = 15.0f;
+ }
+ return _pointsPerSecond;
+}
+
+#pragma mark - Public methods
+
+- (void)startScrolling
+{
+ [self stopScrolling];
+
+ CGFloat animationDuration = (0.5f / self.pointsPerSecond);
+ _scrollTimer = [NSTimer scheduledTimerWithTimeInterval:animationDuration
+ target:self
+ selector:@selector(updateScroll)
+ userInfo:nil
+ repeats:YES];
+}
+
+- (void)stopScrolling
+{
+ [_scrollTimer invalidate];
+ _scrollTimer = nil;
+}
+
+- (void)updateScroll
+{
+ CGFloat animationDuration = _scrollTimer.timeInterval;
+ CGFloat pointChange = self.pointsPerSecond * animationDuration;
+ CGPoint newOffset = self.contentOffset;
+ newOffset.y = newOffset.y + pointChange;
+
+ if (newOffset.y > (self.contentSize.height - self.bounds.size.height))
+ {
+ [self stopScrolling];
+ }
+ else
+ {
+ [UIView beginAnimations:nil context:nil];
+ [UIView setAnimationDuration:animationDuration];
+ self.contentOffset = newOffset;
+ [UIView commitAnimations];
+ }
+}
+
+@end
@@ -0,0 +1,21 @@
+//
+// DAAutoTableView.h
+// DAAutoScroll
+//
+// Created by Daniel Amitay on 2/13/12.
+// Copyright (c) 2012 Daniel Amitay. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface DAAutoTableView : UITableView
+{
+ NSTimer *_scrollTimer;
+}
+
+@property (nonatomic) CGFloat pointsPerSecond;
+
+- (void)startScrolling;
+- (void)stopScrolling;
+
+@end
@@ -0,0 +1,110 @@
+//
+// DAAutoTableView.m
+// DAAutoScroll
+//
+// Created by Daniel Amitay on 2/13/12.
+// Copyright (c) 2012 Daniel Amitay. All rights reserved.
+//
+
+#import "DAAutoTableView.h"
+
+@implementation DAAutoTableView
+
+@synthesize pointsPerSecond = _pointsPerSecond;
+
+- (void)willMoveToWindow:(UIWindow *)newWindow
+{
+ [super willMoveToWindow:newWindow];
+ if(newWindow)
+ {
+ [self.panGestureRecognizer addTarget:self action:@selector(gestureDidChange:)];
+ [self.pinchGestureRecognizer addTarget:self action:@selector(gestureDidChange:)];
+ }
+ else
+ {
+ [self stopScrolling];
+ [self.panGestureRecognizer removeTarget:self action:@selector(gestureDidChange:)];
+ [self.pinchGestureRecognizer removeTarget:self action:@selector(gestureDidChange:)];
+ }
+}
+
+#pragma mark - Touch methods
+
+- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
+{
+ [self stopScrolling];
+ return [super touchesShouldBegin:touches withEvent:event inContentView:view];
+}
+
+- (void)gestureDidChange:(UIGestureRecognizer *)gesture
+{
+ switch (gesture.state)
+ {
+ case UIGestureRecognizerStateBegan:
+ {
+ [self stopScrolling];
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+- (BOOL)becomeFirstResponder
+{
+ [self stopScrolling];
+ return [super becomeFirstResponder];
+}
+
+#pragma mark - Property methods
+
+- (CGFloat)pointsPerSecond
+{
+ if (!_pointsPerSecond)
+ {
+ _pointsPerSecond = 15.0f;
+ }
+ return _pointsPerSecond;
+}
+
+#pragma mark - Public methods
+
+- (void)startScrolling
+{
+ [self stopScrolling];
+
+ CGFloat animationDuration = (0.5f / self.pointsPerSecond);
+ _scrollTimer = [NSTimer scheduledTimerWithTimeInterval:animationDuration
+ target:self
+ selector:@selector(updateScroll)
+ userInfo:nil
+ repeats:YES];
+}
+
+- (void)stopScrolling
+{
+ [_scrollTimer invalidate];
+ _scrollTimer = nil;
+}
+
+- (void)updateScroll
+{
+ CGFloat animationDuration = _scrollTimer.timeInterval;
+ CGFloat pointChange = self.pointsPerSecond * animationDuration;
+ CGPoint newOffset = self.contentOffset;
+ newOffset.y = newOffset.y + pointChange;
+
+ if (newOffset.y > (self.contentSize.height - self.bounds.size.height))
+ {
+ [self stopScrolling];
+ }
+ else
+ {
+ [UIView beginAnimations:nil context:nil];
+ [UIView setAnimationDuration:animationDuration];
+ self.contentOffset = newOffset;
+ [UIView commitAnimations];
+ }
+}
+
+@end
@@ -0,0 +1,21 @@
+//
+// DAAutoTextView.h
+// DAAutoScroll
+//
+// Created by Daniel Amitay on 2/13/12.
+// Copyright (c) 2012 Daniel Amitay. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface DAAutoTextView : UITextView
+{
+ NSTimer *_scrollTimer;
+}
+
+@property (nonatomic) CGFloat pointsPerSecond;
+
+- (void)startScrolling;
+- (void)stopScrolling;
+
+@end
@@ -0,0 +1,110 @@
+//
+// DAAutoTextView.m
+// DAAutoScroll
+//
+// Created by Daniel Amitay on 2/13/12.
+// Copyright (c) 2012 Daniel Amitay. All rights reserved.
+//
+
+#import "DAAutoTextView.h"
+
+@implementation DAAutoTextView
+
+@synthesize pointsPerSecond = _pointsPerSecond;
+
+- (void)willMoveToWindow:(UIWindow *)newWindow
+{
+ [super willMoveToWindow:newWindow];
+ if(newWindow)
+ {
+ [self.panGestureRecognizer addTarget:self action:@selector(gestureDidChange:)];
+ [self.pinchGestureRecognizer addTarget:self action:@selector(gestureDidChange:)];
+ }
+ else
+ {
+ [self stopScrolling];
+ [self.panGestureRecognizer removeTarget:self action:@selector(gestureDidChange:)];
+ [self.pinchGestureRecognizer removeTarget:self action:@selector(gestureDidChange:)];
+ }
+}
+
+#pragma mark - Touch methods
+
+- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
+{
+ [self stopScrolling];
+ return [super touchesShouldBegin:touches withEvent:event inContentView:view];
+}
+
+- (void)gestureDidChange:(UIGestureRecognizer *)gesture
+{
+ switch (gesture.state)
+ {
+ case UIGestureRecognizerStateBegan:
+ {
+ [self stopScrolling];
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+- (BOOL)becomeFirstResponder
+{
+ [self stopScrolling];
+ return [super becomeFirstResponder];
+}
+
+#pragma mark - Property methods
+
+- (CGFloat)pointsPerSecond
+{
+ if (!_pointsPerSecond)
+ {
+ _pointsPerSecond = 15.0f;
+ }
+ return _pointsPerSecond;
+}
+
+#pragma mark - Public methods
+
+- (void)startScrolling
+{
+ [self stopScrolling];
+
+ CGFloat animationDuration = (0.5f / self.pointsPerSecond);
+ _scrollTimer = [NSTimer scheduledTimerWithTimeInterval:animationDuration
+ target:self
+ selector:@selector(updateScroll)
+ userInfo:nil
+ repeats:YES];
+}
+
+- (void)stopScrolling
+{
+ [_scrollTimer invalidate];
+ _scrollTimer = nil;
+}
+
+- (void)updateScroll
+{
+ CGFloat animationDuration = _scrollTimer.timeInterval;
+ CGFloat pointChange = self.pointsPerSecond * animationDuration;
+ CGPoint newOffset = self.contentOffset;
+ newOffset.y = newOffset.y + pointChange;
+
+ if (newOffset.y > (self.contentSize.height - self.bounds.size.height))
+ {
+ [self stopScrolling];
+ }
+ else
+ {
+ [UIView beginAnimations:nil context:nil];
+ [UIView setAnimationDuration:animationDuration];
+ self.contentOffset = newOffset;
+ [UIView commitAnimations];
+ }
+}
+
+@end
Oops, something went wrong.

0 comments on commit 50caa94

Please sign in to comment.