我的应用程序处理图像视图,我想通过触摸在整个视图中拖动图像。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ // This gets you starting position of
UITouch *touch = [ [ event allTouches ] anyObject ] ;
float touchXBeginPoint = [ touch locationInView:touch.view ].x ;
float touchYBeginPoint = [ touch locationInView:touch.view ].y ;
// Calculate the offset between the current image center and the touched points.
touchOffset = hairImage.center.x - touchXBeginPoint;
touchOffset1=hairImage.center.y-touchYBeginPoint;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [ [ event allTouches ] anyObject ] ;
float distanceMoved =( [ touch locationInView:touch.view ].x + touchOffset ) - hairImage.center.x ;
float distanceMoved1=([touch locationInView:touch.view].y+touchOffset)-hairImage.center.y;
float newX = hairImage.center.x + distanceMoved;//+distanceMoved1 ;
float newY=hairImage.center.y+distanceMoved1;
if( newX > 70 && newX < 150 ){ // setting the boundaries
hairImage.center = CGPointMake(newX, hairImage.center.y) ;}
if(newY>100 && newY<180){
hairImage.center=CGPointMake(newY, hairImage.center.x);
}}
这是代码。在这里,我可以沿X方向成功移动imageview,但我的目标是在整个视图中移动imageview。
答案 0 :(得分:0)
关于你的问题的更多信息有帮助...就像你尝试过的,你被困在哪里等等。无论如何我只是复制粘贴你的标题问题和Google搜索..这是第一个结果