File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,4 +16,42 @@ -(UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
1616 return self;
1717}
1818
19+ -(id )initWithFrame : (CGRect)frame
20+ {
21+ if (self = [super initWithFrame: frame]) {
22+ [self setUserInteractionEnabled: YES ];
23+ }
24+ return self;
25+ }
26+
27+
28+ - (CGRect)zoomRectForScrollView : (UIScrollView *)scrollView
29+ withScale : (float )scale withCenter : (CGPoint)center {
30+
31+ CGRect zoomRect;
32+ zoomRect.size .height = scrollView.frame .size .height / scale;
33+ zoomRect.size .width = scrollView.frame .size .width / scale;
34+ zoomRect.origin .x = center.x - (zoomRect.size .width / 2.0 );
35+ zoomRect.origin .y = center.y - (zoomRect.size .height / 2.0 );
36+
37+ return zoomRect;
38+ }
39+
40+ - (void )touchesEnded : (NSSet *)touches withEvent : (UIEvent *)event
41+ {
42+ UITouch* touch = [touches anyObject ];
43+ if ([touch tapCount ] == 2 ) {
44+ UIScrollView* scrollView = (UIScrollView*)self.superview ;
45+
46+ CGRect zoomRect;
47+ if (scrollView.zoomScale > 1.0 ) {
48+ zoomRect = scrollView.bounds ;
49+ } else {
50+ zoomRect = [self zoomRectForScrollView: scrollView
51+ withScale: 2.0
52+ withCenter: [touch locationInView: nil ]];
53+ }
54+ [scrollView zoomToRect: zoomRect animated: YES ];
55+ }
56+ }
1957@end
You can’t perform that action at this time.
0 commit comments