0

私のアプリケーションでドラッグオプションを使用しています。オブジェクトを同じ位置に設定したいので、つまり同じ位置にドラッグして戻した後、他の位置に設定するようにコーディングしてみました。これにどのような変更を加える必要がありますか。

- (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);
}
4

1 に答える 1

1

.h

CGPoint startPt;

.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);
}
于 2013-01-17T05:32:07.500 に答える