gpt4 book ai didi

ios - 拖动随 touchesMoved 闪烁的图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:11:30 26 4
gpt4 key购买 nike

我的图片似乎在我每次更新时触摸的位置下方渲染。另一次它按预期进行。

我希望图像从上次移动时开始移动偏移量,而不会闪烁回到触摸位置。我该怎么做?

代码如下:

int xposStamp;
int yposStamp;

int lastxposStamp;
int lastyposStamp;


- (void) touchesEnded: (NSSet *) touches
withEvent: (UIEvent *) event
{
lastxposStamp = xposStamp;
lastyposStamp = yposStamp;
NSLog(@"touchesEndedCalled");

}

- (void) touchesMoved: (NSSet *) touches
withEvent: (UIEvent *) event
{
if([touches count] == 1){

CGPoint touchPoint = [[touches anyObject] locationInView:_photoImageView];

CGRect rect = _draggableImageView.frame;

int xOffset = touchPoint.x-rect.origin.x;
int yOffset = touchPoint.y-rect.origin.y;

rect.origin.x = lastxposStamp+xOffset;
rect.origin.y = lastyposStamp+yOffset;

_draggableImageView.frame = rect;

//xpos and y pos of the stamp

xposStamp = rect.origin.x;
yposStamp = rect.origin.y;

NSLog(@"xpos: %d, ypos: %d", xposStamp, yposStamp);
}
}

还有一个 NSLog:

2013-08-19 14:25:52.898 JABImageMerge[2292:907] xpos: -11, ypos: 206
2013-08-19 14:25:52.914 JABImageMerge[2292:907] xpos: 133, ypos: 204
2013-08-19 14:25:52.930 JABImageMerge[2292:907] xpos: -16, ypos: 215
2013-08-19 14:25:52.946 JABImageMerge[2292:907] xpos: 128, ypos: 212
2013-08-19 14:25:52.962 JABImageMerge[2292:907] xpos: -19, ypos: 222
2013-08-19 14:25:52.978 JABImageMerge[2292:907] xpos: 124, ypos: 218
2013-08-19 14:25:52.994 JABImageMerge[2292:907] xpos: -21, ypos: 225
2013-08-19 14:25:53.010 JABImageMerge[2292:907] xpos: 121, ypos: 221
2013-08-19 14:25:53.026 JABImageMerge[2292:907] xpos: -22, ypos: 226
2013-08-19 14:25:53.042 JABImageMerge[2292:907] xpos: 120, ypos: 222
2013-08-19 14:25:53.058 JABImageMerge[2292:907] xpos: -21, ypos: 227
2013-08-19 14:25:53.074 JABImageMerge[2292:907] touchesEndedCalled

设置使用此代码的演示应用程序:

  • photoImageView 是一个 ImageView 。
  • draggableImageView 是一个 ImageView 。
  • 实现了 UIGestureRecognizerDelegate

希望有人能帮我解决这个难题。我不是最数学的程序员。

最佳答案

答案如下:

将此添加到您的 .m 文件中。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

不要使用 TouchesMoved。而是使用平移手势在 View 中移动:

- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer
{

CGPoint translation = [panRecognizer translationInView:self.view];
CGPoint imageViewPosition = self.draggableImage.center;
imageViewPosition.x += translation.x;
imageViewPosition.y += translation.y;

self.draggableImage.center = imageViewPosition;
[panRecognizer setTranslation:CGPointZero inView:self.view];

}

关于ios - 拖动随 touchesMoved 闪烁的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18315144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com