@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
@ NOMAD:它在子視圖在同一個類中時有效。但是我的子視圖是其他UIVIEW類的子類, itouch方法從其他類中使用。此外,該子視圖不只是在滾動視圖縮放時才觸摸,否則其工作正常 –
需要一些代碼...) –
@ nomad我做了這個,只是當用戶觸摸子視圖時,縮放scrollview滾動禁用 –