当我缩放视图时,滚动不起作用。如何解决这个问题?谢谢。
- (void)viewDidLoad
{
[super viewDidLoad];
NSInteger count = 10;
NSInteger w = self.view.bounds.size.width;
NSInteger h = self.view.bounds.size.height;
UIScrollView* zoomCanvas;
UIScrollView* scrollCanvas;
zoomCanvas = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, w, h)];
[zoomCanvas setMinimumZoomScale:1.0];
[zoomCanvas setMaximumZoomScale:2.0];
[zoomCanvas setDelegate:self];
scrollCanvas = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, w, h)];
[scrollCanvas setContentSize:CGSizeMake(w, h*count)];
srand(time(NULL));
for (int i=0; i<count; i++) {
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, h*i, w, h)];
view.backgroundColor = [UIColor colorWithRed:rand() % 255 / 255.0 green:rand() % 255 / 255.0 blue:rand() % 255 / 255.0 alpha:1.0];
[scrollCanvas addSubview:view];
}
[zoomCanvas addSubview:scrollCanvas];
[self.view addSubview:zoomCanvas];
}
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [[scrollView subviews] objectAtIndex:0];
}
当我缩放视图时,滚动不起作用。如何解决这个问题?谢谢。