我在 scrollview 中添加了一些 uiimageview,现在想要在触摸 uiimageview 时执行一些操作。但是我的触摸委托方法没有被调用。以下是我的代码:
int x = 0;
for (int i = 0; i < [arr count]; i++){
UIImageView *myImageview = [[UIImageView alloc] initWithFrame:CGRectMake(x, 0, 320, self.view.frame.size.height-45)];
myImageview.userInteractionEnabled = TRUE;
myImageview.opaque = YES;
//[myImageview setImage:[arr objectAtIndex:i]];
myImageview.tag = 100+i;
[scrollvw addSubview:myImageview];
[myImageview setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[(NSDictionary*)[arr objectAtIndex:i] objectForKey:@"image"]]] placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
//reload data here
myImageview.image = image;
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
//handle errors here
}];
x += myImageview.frame.size.width;
}
[scrollvw setContentSize:CGSizeMake(x, self.view.frame.size.height-45)];
我添加了以下方法,但它不起作用:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
if (touch.view.tag > 0) {
touch.view.center = location;
}
NSLog(@"tag=%@", [NSString stringWithFormat:@"%i", touch.view.tag]);
}
有人可以帮我调用触摸委托方法吗?
问候
潘卡伊