diff options
Diffstat (limited to 'Classes/CocosOverlayScrollView.m')
-rwxr-xr-x | Classes/CocosOverlayScrollView.m | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/Classes/CocosOverlayScrollView.m b/Classes/CocosOverlayScrollView.m new file mode 100755 index 0000000..dee9dfe --- /dev/null +++ b/Classes/CocosOverlayScrollView.m | |||
@@ -0,0 +1,106 @@ | |||
1 | // | ||
2 | // CocosOverlayScrollView.m | ||
3 | // shapes | ||
4 | // | ||
5 | // Created by Nate Murray on 8/23/10. | ||
6 | // Copyright 2010 LittleHiccup. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import "CocosOverlayScrollView.h" | ||
10 | |||
11 | @implementation CocosOverlayScrollView | ||
12 | @synthesize targetLayer; | ||
13 | |||
14 | // Configure your favorite UIScrollView options here | ||
15 | -(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer pageControl:(UIPageControl *)m_pageControl{ | ||
16 | if ((self = [super initWithFrame: frameRect])){ | ||
17 | self.contentSize = CGSizeMake(width*numPages, 320); | ||
18 | self.bounces = YES; | ||
19 | self.delaysContentTouches = NO; | ||
20 | self.delegate = self; | ||
21 | self.pagingEnabled = YES; | ||
22 | self.scrollsToTop = NO; | ||
23 | self.showsVerticalScrollIndicator = NO; | ||
24 | self.showsHorizontalScrollIndicator = NO; | ||
25 | [self setUserInteractionEnabled:TRUE]; | ||
26 | [self setScrollEnabled:TRUE]; | ||
27 | self.targetLayer = layer; | ||
28 | // self.canCancelContentTouches = YES; | ||
29 | pageControl = m_pageControl; | ||
30 | } | ||
31 | return self; | ||
32 | } | ||
33 | |||
34 | -(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event | ||
35 | { | ||
36 | if (!self.dragging) | ||
37 | { | ||
38 | // UITouch* touch = [[touches allObjects] objectAtIndex:0]; | ||
39 | // CGPoint location = [touch locationInView: [[touch view] superview]]; | ||
40 | // CCLOG(@"touch at l.x:%f l.y:%f", location.x, location.y); | ||
41 | |||
42 | [self.nextResponder touchesBegan: touches withEvent:event]; | ||
43 | [[[CCDirector sharedDirector] openGLView] touchesBegan:touches withEvent:event]; | ||
44 | } | ||
45 | |||
46 | [super touchesBegan: touches withEvent: event]; | ||
47 | } | ||
48 | |||
49 | -(void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event | ||
50 | { | ||
51 | if (!self.dragging) | ||
52 | { | ||
53 | [self.nextResponder touchesEnded: touches withEvent:event]; | ||
54 | [[[CCDirector sharedDirector] openGLView] touchesEnded:touches withEvent:event]; | ||
55 | } | ||
56 | |||
57 | [super touchesEnded: touches withEvent: event]; | ||
58 | } | ||
59 | |||
60 | -(void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event | ||
61 | { | ||
62 | // if (!self.dragging) | ||
63 | // { | ||
64 | // CCLOG(@"CocosOverlayScrollView touchesEnded not dragging"); | ||
65 | [self.nextResponder touchesCancelled: touches withEvent:event]; | ||
66 | [[[CCDirector sharedDirector] openGLView] touchesCancelled:touches withEvent:event]; | ||
67 | // } | ||
68 | [super touchesCancelled: touches withEvent: event]; | ||
69 | } | ||
70 | |||
71 | |||
72 | - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView | ||
73 | { | ||
74 | // TODO - Custom code for handling deceleration of the scroll view | ||
75 | } | ||
76 | |||
77 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView | ||
78 | { | ||
79 | CGPoint dragPt = [scrollView contentOffset]; | ||
80 | dragPt = [[CCDirector sharedDirector] convertToGL:dragPt]; | ||
81 | |||
82 | dragPt.y = dragPt.y * -1; | ||
83 | dragPt.x = dragPt.x * -1; | ||
84 | |||
85 | CGPoint newLayerPosition = CGPointMake(dragPt.x, dragPt.y); | ||
86 | |||
87 | [targetLayer setPosition:newLayerPosition]; | ||
88 | } | ||
89 | |||
90 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView | ||
91 | { | ||
92 | // CGPoint dragPt = [scrollView contentOffset]; | ||
93 | // etc. | ||
94 | } | ||
95 | |||
96 | -(void) dealloc { | ||
97 | self.targetLayer = nil; | ||
98 | [super dealloc]; | ||
99 | } | ||
100 | |||
101 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView | ||
102 | { | ||
103 | [pageControl setCurrentPage:(NSUInteger)([scrollView contentOffset].x / [scrollView frame].size.width)]; | ||
104 | } | ||
105 | |||
106 | @end \ No newline at end of file | ||