gpt4 book ai didi

iphone - 拖回同一位置

转载 作者:行者123 更新时间:2023-11-29 04:11:19 24 4
gpt4 key购买 nike

我在我的应用程序中使用拖动选项,因为我想将对象设置在相同的位置,即拖回到相同的位置后,我尝试使用以下编码将其设置为其他位置,我应该做什么改变这个,

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
if (touchPoint.x > self.img1.frame.origin.x &&
touchPoint.x < self.img1.frame.origin.x + self.img1.frame.size.width &&
touchPoint.y > self.img1.frame.origin.y &&
touchPoint.y < self.img1.frame.origin.y + self.img1.frame.size.height )
{
self.img1.backgroundColor = self.img1.backgroundColor;

}
self.img1.frame = CGRectMake(self.homePosition.x, self.homePosition.y,
self.img1.frame.size.width,
self.img1.frame.size.height);
}

最佳答案

.h

CGPoint起始点;

.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
startPt = [[touches anyObject] locationInView:self.view];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
if (touchPoint.x > self.img1.frame.origin.x &&
touchPoint.x < self.img1.frame.origin.x + self.img1.frame.size.width &&
touchPoint.y > self.img1.frame.origin.y &&
touchPoint.y < self.img1.frame.origin.y + self.img1.frame.size.height )
{
self.img1.backgroundColor = self.img1.backgroundColor;

}
self.img1.frame = CGRectMake(startPt.x, startPt.y,
self.img1.frame.size.width,
self.img1.frame.size.height);
}

关于iphone - 拖回同一位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14372040/

24 4 0