41 - (void)setDocumentView:(
CPView)aView
43 if (_documentView == aView)
52 name:CPViewFrameDidChangeNotification
53 object:_documentView];
57 name:CPViewBoundsDidChangeNotification
58 object:_documentView];
60 [_documentView removeFromSuperview];
63 _documentView = aView;
69 [_documentView setPostsFrameChangedNotifications:YES];
70 [_documentView setPostsBoundsChangedNotifications:YES];
74 selector:@selector(viewFrameChanged:)
75 name:CPViewFrameDidChangeNotification
76 object:_documentView];
80 selector:@selector(viewBoundsChanged:)
81 name:CPViewBoundsDidChangeNotification
82 object:_documentView];
100 - (CGPoint)constrainScrollPoint:(CGPoint)aPoint
103 return _CGPointMakeZero();
105 var documentFrame = [_documentView frame];
107 aPoint.x = MAX(0.0, MIN(aPoint.x, MAX(_CGRectGetWidth(documentFrame) - _CGRectGetWidth(_bounds), 0.0)));
108 aPoint.y = MAX(0.0, MIN(aPoint.y, MAX(_CGRectGetHeight(documentFrame) - _CGRectGetHeight(_bounds), 0.0)));
113 - (void)setBoundsOrigin:(CGPoint)aPoint
115 if (_CGPointEqualToPoint(_bounds.origin, aPoint))
124 scrollViewClass = objj_getClass(
"CPScrollView");
126 if ([superview isKindOfClass:scrollViewClass])
134 - (void)scrollToPoint:(CGPoint)aPoint
145 [
self _constrainScrollPoint];
154 [
self _constrainScrollPoint];
157 - (void)resizeSubviewsWithOldSize:(CGSize)aSize
160 [
self _constrainScrollPoint];
163 - (void)_constrainScrollPoint
165 var oldScrollPoint = [
self bounds].origin;
169 [
self scrollToPoint:oldScrollPoint];
173 if (!CGPointEqualToPoint(oldScrollPoint, [
self bounds].origin))
177 var superview = [
self superview],
181 scrollViewClass = objj_getClass(
"CPScrollView");
183 if ([superview isKindOfClass:scrollViewClass])
184 [superview reflectScrolledClipView:self];
189 var bounds = [
self bounds],
195 if (CGRectContainsPoint(bounds, eventLocation))
198 if (![superview isKindOfClass:[
CPScrollView class]] || [superview hasVerticalScroller])
200 if (eventLocation.y < CGRectGetMinY(bounds))
201 deltaY = CGRectGetMinY(bounds) - eventLocation.y;
202 else if (eventLocation.y > CGRectGetMaxY(bounds))
203 deltaY = CGRectGetMaxY(bounds) - eventLocation.y;
204 if (deltaY < -bounds.size.height)
205 deltaY = -bounds.size.height;
206 if (deltaY > bounds.size.height)
207 deltaY = bounds.size.height;
210 if (![superview isKindOfClass:[
CPScrollView class]] || [superview hasHorizontalScroller])
212 if (eventLocation.x < CGRectGetMinX(bounds))
213 deltaX = CGRectGetMinX(bounds) - eventLocation.x;
214 else if (eventLocation.x > CGRectGetMaxX(bounds))
215 deltaX = CGRectGetMaxX(bounds) - eventLocation.x;
216 if (deltaX < -bounds.size.width)
217 deltaX = -bounds.size.width;
218 if (deltaX > bounds.size.width)
219 deltaX = bounds.size.width;
222 return [
self scrollToPoint:CGPointMake(bounds.origin.x - deltaX, bounds.origin.y - deltaY)];
234 if (
self = [super initWithCoder:aCoder])
235 [
self setDocumentView:[aCoder decodeObjectForKey:CPClipViewDocumentViewKey]];
244 [aCoder encodeObject:_documentView forKey:CPClipViewDocumentViewKey];