【发布时间】:2013-02-26 05:53:15
【问题描述】:
我有UIScrollView 和许多UIImageViews。我需要将图像从UIScrollView 拖放到另一个视图。在scrollView touch 之外工作。但是在滚动视图内部触摸不起作用。我使用了touchesBegan,touchesMoved 等方法。请帮我。
-(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]?如果我没记错的话,它默认是禁用的。 -
@IkmalEzzani,UserInteractionEnabled 为 true。但它不起作用。
-
UIScrollView touchesBegan 内部不适用于子视图。只需验证我的答案即可。
-
@Madhu,请提供一些示例代码
-
检查它用示例代码更新了我的答案。
标签: iphone ios uiscrollview uitouch