我有两个UIScrollViews,aScroll和bScroll。而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];
}
答案 0 :(得分:0)
我猜您需要使用scrollViewWillBeginDragging:
检测触摸,如果bScroll是移动的,您可以设置aScroll的属性:
if([scrollView isEqual: bScroll])
aScroll.scrollEnabled = NO;
要稍后恢复动作,您可以使用scrollViewDidEndDecelerating:
aScroll.scrollEnabled = YES;
请记住这些是委托方法,您需要至少将bScroll的委托设置为ViewController
。希望这会有所帮助。