我有UIScrollView
与许多UIImageViews
。我需要将图像从UIScrollView
拖放到另一个视图。在scrollView触摸之外工作。但内部滚动视图触摸不起作用。我用touchesBegan
,touchesMoved
等方法。请帮帮我。检测触摸的UIImage作为UIScrollView子视图添加
-(IBAction)selectBut:(id)sender
{
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(x,y,w,h)];
scrollView.userInteractionEnabled = YES;
int y = 0;
for (int i = 0; i < [myArray count]; i++) {
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, y, 75, 30)];
image.userInteractionEnabled = YES;
y=y+35;
[scrollView addSubview:image];
}
[self.view addSubview:scrollView];
[scrollView setContentSize:CGSizeMake(150, 300)]
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 1) {
NSLog(@"One touch !!");
}
}
你有没有尝试过将UIImageView设置为'[self setUserInteractionEnabled:TRUE]'?其默认情况下禁用,如果我没有错。 – 2013-02-26 05:58:19
@IkmalEzzani,UserInteractionEnabled为true,但它不起作用。 – IKKA 2013-02-26 06:01:16
UIScrollView touchesBegan内部不适用于子视图。只需验证我的答案。 – Madhu 2013-02-26 07:09:33