2011-08-24 7 views
2

내 앱은 이미지 뷰를 처리하므로 이미지를 터치하여 뷰 전체로 드래그하려고합니다.터치를 사용하여 이미지 뷰 드래그

-(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 방향으로 이미지 뷰를 성공적으로 이동할 수 있지만 내 목표는 뷰 전체에서 이미지 뷰를 이동하는 것입니다. 귀하의 질문에

답변

관련 문제