期间,我创建下面的UITouch点的UIButton,我想,当我继续按触摸和动画界达到我的触摸点我执行一些活动存在。CGRectContainsPoint为一个UIButton动画
以下是验证码。
我总是得到x,y 0为UIButton。
- (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;它使我喜欢一旦我点击它给我一个CGRectContainsPoint为真如果我使用CGRect currentRect = self.uiButton.presentationLayer.frame;它给了我一个错误,没有找到属性 – user3042604
所以使用'layer.presentationLayer'。去做一些研究,哥们。 –