【发布时间】:2012-05-31 10:33:31
【问题描述】:
我正在尝试为 UIView 在用户开始拖动时展开动画,并在用户停止拖动时为其折叠动画。在 iOS5 中,这似乎可以工作,虽然并不完美 - 视图在展开时动画移动到当前手指位置(因此滞后),但在展开动画结束时工作正常。
在 iOS4 中,它只是被破坏了 - 视图以动画方式展开,但在动画完成之前根本不会用用户的手指移动。
我能做什么?
- (void)gestureRecognizerMoved:(id)sender
{
[self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
NSLog(@"translated x %f y %f", translatedPoint.x, translatedPoint.y);
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
{
firstX = [sender view].center.x;
firstY = [sender view].center.y;
NSLog(@"first x %f y %f", firstX, firstY);
}
translatedPoint = CGPointMake([sender view].center.x, firstY+translatedPoint.y);
[[sender view] setCenter:translatedPoint];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
{
[UIView animateWithDuration:0.8f animations:^(void)
{
CGRect frame = [sender view].frame;
frame.size.width += 200.0f;
[sender view].frame = frame;
}];
}
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded)
{
[UIView animateWithDuration:0.8f animations:^(void)
{
CGRect frame = [sender view].frame;
frame.size.width -= 200.0f;
[sender view].frame = frame;
}];
}
}
编辑:使用 Core Graphics 仿射变换来调整视图大小(例如 CGAffineTransformMakeScale)而不是修改视图的框架摆脱了 iOS5 中的滞后,所以现在即使在动画期间它也会坚持用户的手指按压,而不是动画到新闻地点,完美!但是在 iOS4 中仍然遇到同样的问题。
【问题讨论】:
-
你试过 UIViewAnimationOptionAllowUserInteraction 作为动画选项吗?
-
这行得通,谢谢!如果是评论,有没有办法可以接受这个作为答案?
-
我把它作为答案发布了
标签: iphone ios animation uiview uipangesturerecognizer