当我缩放视图时,滚动不起作用。
如何解决此问题?
- (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];
}
当我缩放视图时,滚动不起作用。
如何解决此问题?
最佳答案
如果您正在谈论在缩放画布中滚动,则可能是因为您未设置其内容大小。
关于ios - 缩放和滚动 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19697570/