0

我正在开发一个应用程序,我只想在 Y 轴上移动 UIImage,而不是在 X 轴上,这就是我到目前为止所做的

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
 stretchPoint = [[touches anyObject]locationInView:self.view];
 arrowImage.center = 拉伸点;

}

上面的代码是在两个轴上移动箭头图像,stretchPoint 是 CGPoint 的一个实例,我的应用程序处于纵向模式,谁能给我一个基本的想法如何做到这一点,因为箭头图像是 UIImageView 的一个实例。

4

4 回答 4

1

这应该可以正常工作:

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];

        CGPoint currentPoint = [touch locationInView:self.view];
        currentPoint.x = arrowImage.center.x;

        arrowImage.center = currentPoint;
    }
于 2011-01-21T10:38:25.447 回答
1

子类化 UIImage 并实现以下代码

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:[self superview]];


    CGPoint newCenter = CGPointMake(self.center.x, currentPoint.y);
    self.center = newCenter;


}
于 2014-01-31T10:34:30.627 回答
0

我不确定是否没有测试,但你可以实现这样的东西:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:self.view];
    currentPoint.y = 20;
}
于 2011-01-21T10:27:43.930 回答
0

就像是:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    stretchPoint = [[touches anyObject] locationInView:self.view];
    arrowImage.frame = CGPointMake(arrowImage.origin.x, 
                                   stretchPoint.y, 
                                   arrowImage.size.width,
                                   arrowImage.size.height);

}
于 2011-01-21T12:31:52.490 回答