Iphone 将图像从carousal拖动到imageview
我想从图像的旋转木马中拖动图像,并将其放在另一个图像视图中。拖动图像后,应将其从旋转木马中删除。我已经为此编写了代码,该代码也将从旋转木马中删除。 我使用触摸事件 但问题是,当我触摸屏幕上的任何地方时,拖动一个图像后,它会自动选择下一个图像。我如何停止它?我想在单击图像时拖动它 我的密码Iphone 将图像从carousal拖动到imageview,iphone,objective-c,ipad,Iphone,Objective C,Ipad,我想从图像的旋转木马中拖动图像,并将其放在另一个图像视图中。拖动图像后,应将其从旋转木马中删除。我已经为此编写了代码,该代码也将从旋转木马中删除。 我使用触摸事件 但问题是,当我触摸屏幕上的任何地方时,拖动一个图像后,它会自动选择下一个图像。我如何停止它?我想在单击图像时拖动它 我的密码 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouche
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
btnBackImg.center = location;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint pointMoved = [touch locationInView:self.view];
btnBackImg.frame = CGRectMake(pointMoved.x, pointMoved.y, btnBackImg.frame.size.width,btnBackImg.frame.size.height);
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touch end");
if (btnBackImg != nil)
{
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint(basket_image.frame, [touch locationInView:self.view]))
{
basket_image.image=[UIImage imageNamed:[NSString stringWithFormat:@"wit_bas.png"]];
[self.product_categories removeObjectAtIndex:imgIndex+1];
[carousel reloadData];
}
}
}
在此btnCackImg中,您希望搬入basketImg。
如果有人知道,请帮助我,如果有任何链接,那么也很有用。
提前感谢。您已在触摸中使用此代码。开始
CGPoint location=[touch location inview:touch.view]
其中touch.View
表示触摸视图中的所有对象,即self.View
。您真正需要的是添加要放置的图像的名称,而不是touch.View。这将一次选择图像
CGPoint location = [touch locationInView:imageName];