gpt4 book ai didi

iphone - With touches - 如何在到达某个 Y 点时停止 UIIMageView 移动

转载 作者:行者123 更新时间:2023-11-29 13:25:58 25 4
gpt4 key购买 nike

我在屏幕底部有一张图片。

我希望用户向上移动图像,直到它到达某个 Y 点,如下所示:

[door setCenter:CGPointMake(160,347)];

到目前为止,当您向上拖动图像(门)时,它会继续经过我的目的地点,但当您放手时,它会快速回到正确位置。

如果用户的手指仍在向上滑动,如何在到达某个点时停止图像移动?它会在 if 语句中吗?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (startPoint.y < 347) {
// something in here ?????
}
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *myTouch = [touches anyObject];
startPoint = [myTouch locationInView:self.view];
NSLog(@"position = %f and %f",startPoint.x,startPoint.y);
[door setCenter:CGPointMake(160, startPoint.y)];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[door setCenter:CGPointMake(160,347)];
}

最佳答案

如何在 touchesMoved 方法中设置它。类似的东西,

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *myTouch = [touches anyObject];
startPoint = [myTouch locationInView:self.view];
NSLog(@"position = %f and %f",startPoint.x,startPoint.y);
if (startPoint.y < 347) { //or suitable condition to verify your case
[door setCenter:CGPointMake(160, startPoint.y)]; //then only set the center
} else
{
[door setCenter:CGPointMake(160,347);
}
}

关于iphone - With touches - 如何在到达某个 Y 点时停止 UIIMageView 移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13111694/

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