0
我已經在scrolview中添加了一些uiimageview,現在想要觸摸它執行一些操作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]);
}
能有人幫我在得到被稱爲觸摸委託方法。
問候
潘卡
是的,我用手勢識別器試過,它工作。我仍然想知道爲什麼它不適用於UITouch。 – pankaj