当我缩放视图时,滚动不起作用。 如何解决这个问题?谢谢。
- (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];
}
当我缩放视图时,滚动不起作用。 如何解决这个问题?谢谢。
答案 0 :(得分:0)
如果您正在谈论在缩放画布中滚动,可能是因为您没有设置其内容大小。
答案 1 :(得分:0)
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSInteger count = 10;
NSInteger w = self.view.bounds.size.width;
NSInteger h = self.view.bounds.size.height;
zoomCanvas = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, w, h)];
[zoomCanvas setMinimumZoomScale:1.0];
[zoomCanvas setMaximumZoomScale:2.0];
[zoomCanvas setDelegate:self];
[zoomCanvas setContentSize:CGSizeMake(w, h*count)];
dummyCanvas = [[UIView alloc] initWithFrame:CGRectMake(0, 0 , 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];
[dummyCanvas addSubview:view];
}
[zoomCanvas addSubview:dummyCanvas];
[self.view addSubview:zoomCanvas];
}
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return dummyCanvas;
}