2013-10-31 107 views
2

當我放大視圖時,滾動不起作用。 如何解決此問題?謝謝。放大和滾動視圖

- (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

在縮放畫布中不會出現滾動? – bilobatum

回答

0

如果您正在討論在縮放畫布中滾動,可能是因爲您沒有設置其內容大小。

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; 
} 
相關問題