我嘗試在iPhone應用程序中拖放多個圖像。我在YouTube上看過一個教程,但它不起作用。IOS:拖動多個圖像
我創建的圖像是這樣的:
image1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"button_klein.png"]];
[image1 setFrame:CGRectMake(touchPoint.x-25,touchPoint.y-25,50,50)];
[[self view] addSubview:image1];
image2=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"button2_klein.png"]];
[image2 setFrame:CGRectMake(135,215,50,50)];
[[self view] addSubview:image2];
然後我試圖讓他們dragable這樣:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *myTouch = [[event allTouches] anyObject];
CGPoint location = [myTouch locationInView:self.view];
if ([myTouch view] == image1) {
image1.center = location;
NSLog(@"Test1");
}
if ([myTouch view] == image2) {
image2.center = location;
NSLog(@"Test2");
}
}
但doesn't工作。當我試圖讓一個圖像可拖動時,它就起作用了。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *myTouch = [[event allTouches] anyObject];
image1.center = [myTouch locationInView:myTouch.view];
}
有人可以告訴我,問題在哪裏?
當然可以。 UIImageView是UIView的子類,當然,您可以將任何指針與任何其他指針進行比較。 「比較從未發生」從未發生過。 – 2011-06-20 01:40:43
是的,你可以比較指針。 – boudini 2011-07-28 10:15:52