@interface UIZoomingViewController : UIViewController <UIScrollViewDelegate>
@property (strong, nonatomic) UIView* substrate;
@end
@implementation UIZoomingViewController
-(id)init /*your init method*/
{
if(self = [super init])
{
UIScrollView* scrollView = ((UIScrollView*)self.view); /*controller view - UIScrollView*/
[scrollView setDelegate:self];
/*set contentsize, min max zoom scale*/
_substrate = [UIView alloc] initWithFrame:scrollView.bounds];
[scrollView addSubview:_substrate];
/*
if you need zoom view, add to substrate
[_substrate addSubview:...];
*/
}
return self;
}
#pragma mark - UIScrollView delegate implementation
-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView
{
return _substrate;
}
@end
UIScrollViewの後にタッチを受け取る必要がある場合は、サブクラスを作成してください...
@interface UINewScrollView : UIScrollView
@end
@implementation UINewScrollView
-(BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
return YES;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesMoved:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesEnded:touches withEvent:event];
}
@end