我有一个UIImageView,我在多次单击按钮时添加多个UIImages并在TouchesMoevd的帮助下移动它。 问题是每当我移动UIImage时它会移出UIView。
我希望我的图像只能在UIImageView中移动。
我知道这很容易,但我不知道如何限制特定部分的图像运动???
帮助...
这是我的代码og TouchesMoved Method。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
imgPimple = (UIImageView*)[touch view];
CGPoint touchLocation = [touch locationInView:[imgPimple superview]];
imgPimple.clipsToBounds = YES;
if ([touch.view isKindOfClass:[UIImageView class]])
{
imgPimple.center = touchLocation;
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
答案 0 :(得分:0)
最后我已经解决了这个问题
解决方案是:在toucesMoved方法中使用此代码
UITouch *touch = [[event allTouches] anyObject];
imgPimple = (UIImageView*)[touch view];
CGPoint touchLocation = [touch locationInView:[image superview]];
if (CGRectContainsPoint(CGRectMake(15, 20, 280, 220), touchLocation))
{
if ([touch.view isKindOfClass:[UIImageView class]])
{
imgPimple.center = touchLocation;
}
}