【发布时间】:2013-11-27 16:26:30
【问题描述】:
我正在创建一个跟随 UITouch 点的 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");
}
}
问候 萨拉
【问题讨论】:
标签: ios objective-c animation uibutton