40 - (void)setDocumentView:(
CPView)aView
42 if (_documentView == aView)
46 [_documentView removeFromSuperview];
48 _documentView = aView;
68 - (CGPoint)constrainScrollPoint:(CGPoint)aPoint
71 return CGPointMakeZero();
73 var documentFrame = [_documentView frame];
75 aPoint.x = MAX(0.0, MIN(aPoint.x, MAX(CGRectGetWidth(documentFrame) - CGRectGetWidth(_bounds), 0.0)));
76 aPoint.y = MAX(0.0, MIN(aPoint.y, MAX(CGRectGetHeight(documentFrame) - CGRectGetHeight(_bounds), 0.0)));
81 - (void)setBoundsOrigin:(CGPoint)aPoint
83 if (CGPointEqualToPoint(_bounds.origin, aPoint))
92 scrollViewClass = objj_getClass(
"CPScrollView");
94 if ([superview isKindOfClass:scrollViewClass])
102 - (void)scrollToPoint:(CGPoint)aPoint
113 [
self _constrainScrollPoint];
122 [
self _constrainScrollPoint];
125 - (void)resizeSubviewsWithOldSize:(CGSize)aSize
128 [
self _constrainScrollPoint];
131 - (void)_constrainScrollPoint
133 var oldScrollPoint = [
self bounds].origin;
137 [
self scrollToPoint:oldScrollPoint];
141 if (!CGPointEqualToPoint(oldScrollPoint, [
self bounds].origin))
145 var superview = [
self superview],
149 scrollViewClass = objj_getClass(
"CPScrollView");
151 if ([superview isKindOfClass:scrollViewClass])
152 [superview reflectScrolledClipView:self];
163 if (CGRectContainsPoint(
bounds, eventLocation))
166 if (![superview isKindOfClass:[
CPScrollView class]] || [superview hasVerticalScroller])
168 if (eventLocation.y < CGRectGetMinY(
bounds))
169 deltaY = CGRectGetMinY(
bounds) - eventLocation.y;
170 else if (eventLocation.y > CGRectGetMaxY(
bounds))
171 deltaY = CGRectGetMaxY(
bounds) - eventLocation.y;
172 if (deltaY < -
bounds.size.height)
173 deltaY = -
bounds.size.height;
174 if (deltaY >
bounds.size.height)
175 deltaY =
bounds.size.height;
178 if (![superview isKindOfClass:[
CPScrollView class]] || [superview hasHorizontalScroller])
180 if (eventLocation.x < CGRectGetMinX(
bounds))
181 deltaX = CGRectGetMinX(
bounds) - eventLocation.x;
182 else if (eventLocation.x > CGRectGetMaxX(
bounds))
183 deltaX = CGRectGetMaxX(
bounds) - eventLocation.x;
184 if (deltaX < -
bounds.size.width)
185 deltaX = -
bounds.size.width;
186 if (deltaX >
bounds.size.width)
187 deltaX =
bounds.size.width;
190 return [
self scrollToPoint:CGPointMake(bounds.origin.x - deltaX, bounds.origin.y - deltaY)];
193 - (CGRect)documentVisibleRect
195 return [_documentView visibleRect];
207 if (
self = [super initWithCoder:aCoder])
211 _documentView = [aCoder decodeObjectForKey:CPClipViewDocumentViewKey];
221 [aCoder encodeObject:_documentView forKey:CPClipViewDocumentViewKey];
void addSubview:(CPView aSubview)
void scrollToPoint:(CGPoint aPoint)
CGPoint locationInWindow()
void setBoundsOrigin:(CGPoint aPoint)
CGPoint convertPoint:fromView:(CGPoint aPoint, [fromView] CPView aView)
void encodeWithCoder:(CPCoder aCoder)
A notification that can be posted to a CPNotificationCenter.
void setBoundsOrigin:(CGPoint aPoint)
Defines methods for use when archiving & restoring (enc/decoding).
var CPClipViewDocumentViewKey
CGPoint constrainScrollPoint:(CGPoint aPoint)
void resizeSubviewsWithOldSize:(CGSize aSize)
void reflectScrolledClipView:(CPClipView aClipView)