0

I have two UIScrollViews, aScroll and bScroll. And the bScroll is the aScroll's subView. Problem I am facing is, i want to drag in bScroll and do not affect the aScroll. Can someone help me here?? Thanks.

- (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];
}
  • This is the sample code. When i drag the bLable reaches the edge, aLabel will drag together.This is not my desired, how do i do?? –  Jul 25 '12 at 16:31

1 Answers1

0

My guess is you'd need to detect touches with scrollViewWillBeginDragging: and if bScroll is the one moving you could set aScroll's property:

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

To restore movement later, you could use scrollViewDidEndDecelerating:

aScroll.scrollEnabled = YES;

Remember these are delegate methods, you need to set at least bScroll's delegate to your ViewController. Hope this helps.

ohr
  • 1,717
  • 14
  • 15
  • If the two UIScrollViews at the different UIViewController, and then how to do? –  Jul 26 '12 at 02:38