UITouch 지점을 따르는 UIButton을 만들고 있는데, 계속 누르고 있으면 애니메이션 경계가 내 터치 지점에 도달하여 거기에서 몇 가지 작업을 수행하고 싶습니다.CGRectContainsPoint 애니메이션 도중 UIButton에 대해
다음은 코드입니다.
UIButton에 항상 x, y 0이 표시됩니다.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
if([touches count] == 1) {
UITouch *touch = [touches anyObject];
self.uiButton.center = [touch locationInView:self.view];
}
[UIView commitAnimations];
UITouch *touchTemp = [touches anyObject];
CGPoint pCurrent = [touchTemp locationInView:self.view];
CGRect currentRect = self.uiButton.layer.bounds;
NSLog(@"Current Rect x:%f,Current y:%f",
currentRect.origin.x,
currentRect.origin.y);
NSLog(@"TouchPoint x:%f,TouchPoint y:%f",
pCurrent.x,
pCurrent.y);
if(CGRectContainsPoint(currentRect, pCurrent)) {
NSLog(@"Touched....in rect");
}
}
감사 사라
만약 내가 self.uiButton.frame을 사용한다면; 내가 CGRect currentRect = self.uiButton.presentationLayer.frame을 사용하면 true로 CGRectContainsPoint를 제공합니다. 그것은 나를 찾을 수없는 속성을 찾을 수 없습니다. – user3042604
그래서'layer.presentationLayer'를 사용하십시오. 가서 조사 좀해라, 친구. –