【问题标题】:Dragging the imageview by means of touches通过触摸拖动图像视图
【发布时间】:2011-08-24 06:15:34
【问题描述】:

我的应用程序处理一个图像视图,我想通过触摸将图像拖到整个视图中。

-(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。

【问题讨论】:

    标签: iphone objective-c ios uiimageview touches


    【解决方案1】:

    有关您的问题的更多信息会有所帮助...例如您尝试了什么,卡在哪里等等。无论如何,我只是复制粘贴了您的标题问题并在谷歌上搜索了...这是第一个结果

    http://www.icodeblog.com/2008/10/20/iphone-programming-tutorial-using-uitouch-to-drag-an-image-around-the-screen/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多