【发布时间】:2012-02-25 18:19:27
【问题描述】:
我正在尝试为我的 imageView(下面代码中的 maskPreview)创建移动功能,以便用户可以在屏幕周围移动包含在 maskPreview 中的图片。这是我的触摸开始和触摸移动的代码:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count]==1) {
UITouch *touch= [touches anyObject];
originalOrigin = [touch locationInView:maskPreview];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count]==1) {
UITouch *touch = [touches anyObject];
CGPoint lastTouch = [touch previousLocationInView:self.view];
CGFloat movedDistanceX = originalOrigin.x-lastTouch.x;
CGFloat movedDistanceY = originalOrigin.y-lastTouch.y;
[maskPreview setFrame:CGRectMake(maskPreview.frame.origin.x+movedDistanceX, maskPreview.frame.origin.y + movedDistanceY, maskPreview.frame.size.width, maskPreview.frame.size.height)];
}
}
但我从应用程序中收到了一些奇怪的响应。我没有限制 imageview 可以移动多远,即防止它离开屏幕,但即使是一个小动作,我的 imageview 也会变得疯狂并消失。
在此先感谢大家的帮助
【问题讨论】:
标签: cocoa-touch uiimageview user-interaction