0
我想在屏幕的某个区域移动图像。我不想与框架混淆,因为它会在稍后造成碰撞行为的麻烦。我得到了这个代码到目前为止。我不知道如何使用触摸感谢您的帮助使用CGAffineTransformTranslate通过触摸在特定区域移动图像
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//CGPoint svpt = [[touches anyObject] locationInView:self.view];
CGPoint pt = [[touches anyObject] locationInView:self.playerMove];
CGRect frame = [self.playerMove frame];
CGAffineTransform CGAT = CGAffineTransformIdentity;
CGAT = CGAffineTransformTranslate(CGAT, MIN(MAX(frame.origin.x, -10), 240), MIN(MAX(frame.origin.y, 430), 430));
self.playerMove.transform = CGAT;
}
图像不动...我叫的viewDidLoad中的代码和使用handlePan方法 前两行,还怎么设置区域边界我想移动图像? –
嗯。我刚刚测试过,虽然不完美。这对我有用。请确保playerMove视图具有userInteractionEnabled = YES。 – danh
编辑答案以添加有关userInteractionEnabled的提醒,还改进了泛代码以重置识别之间的翻译状态。 – danh