我想从图像的轮播中拖动图像并将其放在另一个图像视图中。拖动后应该从轮播中删除。我已经为此完成了代码,该代码也将从轮播中删除。我使用了触摸事件。
但问题是,当我触摸屏幕上的其他任何位置时拖动一张图像后,它会自动选择下一张图像。我怎样才能停止它?我想在点击它时拖动图像。
我的代码。
- (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。如果有人知道然后请帮助我,或者如果任何链接也有用。提前致谢。