0

aScrollとbScrollの2つのUIScrollViewがあります。そして、bScrollはaScrollのサブビューです。私が直面している問題は、bScrollをドラッグして、aScrollに影響を与えたくないということです。誰かがここで私を助けることができますか?ありがとう。

- (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];
}
4

1 に答える 1

0

私の推測では、タッチを検出する必要がscrollViewWillBeginDragging:あり、bScroll が動いている場合は、aScroll のプロパティを設定できます。

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

後で動きを復元するには、次を使用できますscrollViewDidEndDecelerating:

aScroll.scrollEnabled = YES;

これらはデリゲート メソッドであることを忘れないでください。少なくとも bScroll のデリゲートを に設定する必要がありますViewController。お役に立てれば。

于 2012-07-25T16:48:46.457 に答える