Chciałbym przeciągnąć UIImage na jedno z kilku UButtonów i zmienić położenie na podstawie którego przycisku przeciągnęłam.Jak się dowiedzieć, na jakim widoku zakończyło się wydarzenie dotykowe?
Problem, na który się natknąłem, polega na tym, że UITouch zapisuje tylko widok, w którym rozpoczął się mój dotyk. Chciałbym uzyskać dostęp do widoku, na którym kończy się mój dotyk. Jak mogę to zrobić?
Kod:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
dealerBtnOrigin = [touch locationInView:self.view];
//NSLog(@"%u %u",touch.view.tag, ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]).tag);
//CHECK TO SEE WHICH BUTTON WAS TOUCHED
if (touch.view == ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]))
{
((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]).center = location;
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
if (touch.view == ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]))
{
((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]).center = location;
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
UIView *endView = [self.view hitTest:location withEvent:nil];
if (touch.view == ((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]))
{
NSLog(@"%u %u",endView.tag, touch.view.tag);
if([buttons containsObject:(UIButton *)endView])
{
[[dealerBtns objectAtIndex:[table getButtonSeat]] setHidden:YES];
[table passButton:touch.view.tag];
[[dealerBtns objectAtIndex: touch.view.tag] setHidden:NO];
}
((UIView *)[dealerBtns objectAtIndex:[table getButtonSeat]]).center = dealerBtnOrigin;
}
}
Nie sądzę, żebym mógł skorzystać z ręcznego rozwiązania za pomocą współrzędnych CGPoint, aby dowiedzieć się, który przycisk jest używany, ponieważ używam wielu scenorysów dla różnych rozmiarów ekranu/urządzeń. – Deco