【问题标题】:how move an image on mainview如何在主视图上移动图像
【发布时间】:2011-07-06 08:12:45
【问题描述】:

我遇到了 iPhone SDK 的问题。 我想创建一个用户可以随意触摸、移动和缩放的 imageView。

我该怎么做?

谢谢

【问题讨论】:

    标签: iphone uiimageview move scale crop


    【解决方案1】:
     - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
             [UIView beginAnimations:nil context:NULL]; 
             CGPoint touchPoint = [[touches anyObject] locationInView:[self window]];
             float deltaX = touchPoint.x - lastUpdatedPoint.x;
             float deltaY = touchPoint.y - lastUpdatedPoint.y;
             float newCenterX = [[self layer] position].x + deltaX; float newCenterY = [[self layer] position].y + deltaY;
             CGPoint center = CGPointMake(newCenterX, newCenterY);
             [[self layer] setPosition:center]; 
             lastUpdatedPoint = touchPoint;
             [UIView commitAnimations];
           }
    

    由 CNSivakumar

    【讨论】:

      【解决方案2】:

      简单的方法是将它放在 UIScrollView 中并启用您不想使用的 UIScrollViewDelegate 的方法(滚动/缩放)

      看一下苹果示例项目“PhotoScroller”,可以在xCode帮助中找到...

      乔, 卢卡

      【讨论】:

        【解决方案3】:

        为了移动一个物体,你可以通过 CGAfflineTransformation 从 x 轴移动到 y 轴。

        你在 Touch Delegates 中写下这些代码。还将 UIImage 框架设置为 CGRectZero。

                    [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:.50];
            titl.transform=CGAffineTransformMakeTranslation(260, 0);
            comment.transform=CGAffineTransformMakeTranslation(0, 100); 
            [UIView commitAnimations];
        

        这是将对象从一个地方移动到另一个地方的代码。这可能会帮助你

        【讨论】:

          【解决方案4】:

          查看 UIGestureRecognizer :http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html

          尤其是 UIPanGestureRecognizer 和 UIPinchGestureRecognizer

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-12-29
            • 2019-05-11
            • 1970-01-01
            • 2023-04-09
            • 2021-02-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多