0

我有兩個UIScrollViews,aScroll和bScroll。而bScroll是aScroll的子視圖。我面臨的問題是,我想拖動bScroll並且不會影響aScroll。 有人可以幫我嗎? 謝謝。拖動兩個UIScrollViews

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
UIScrollView *aScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(50, 50, 400, 400)]; 
aScroll.backgroundColor = [UIColor grayColor]; 
aScroll.contentSize = CGSizeMake(401, 401); 
[self.view addSubview:aScroll]; 
[aScroll release]; 

UIScrollView *bScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(75, 75, 150, 150)]; 
bScroll.backgroundColor = [UIColor lightGrayColor]; 
bScroll.contentSize = CGSizeMake(500, 500); 
[aScroll addSubview:bScroll]; 
[bScroll release]; 

UILabel *bLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 30, 30)]; 
bLabel.text = @"B"; 
[bScroll addSubview:bLabel]; 
[bLabel release]; 

UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 250, 100, 40)]; 
aLabel.text = @"A"; 
[aScroll addSubview:aLabel]; 
[aLabel release]; 
} 
+0

這是示例代碼。當我拖動bLable到達邊緣時,aLabel會一起拖動。這不是我想要的,我該怎麼辦? – user1552201 2012-07-25 16:31:57

回答

0

我的猜測是你需要檢測與scrollViewWillBeginDragging:感動,如果bScroll是一個運動,你可以設置aScroll的財產:

if([scrollView isEqual: bScroll]) 
aScroll.scrollEnabled = NO; 

日後若要恢復的運動,你可以使用scrollViewDidEndDecelerating:

aScroll.scrollEnabled = YES; 

記住這些是委託方法,您需要至少將bScroll的委託設置爲您的ViewController。希望這可以幫助。

+0

如果兩個UIScrollViews在不同的UIViewController上,那該怎麼辦? – user1552201 2012-07-26 02:38:42

+0

我試過了,但失敗了 – user1552201 2012-07-26 03:56:45