我試圖在用戶開始拖動時展開UIView動畫,並在停止拖動時爲其摺疊動畫。在iOS5中,這似乎工作,雖然不完美 - 視圖動畫在擴展(如此延遲)時移動到當前手指位置,但在擴展動畫完成時工作正常。在拖動時動畫UIView
在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;
}];
}
}
編輯:使用核芯顯卡仿射變換來調整視圖(例如CGAffineTransformMakeScale),而不是修改視圖的框架擺脫在iOS5中的滯後性,所以現在即使在動畫堅持以用戶的手指按壓,而不是動畫到新聞的位置,完美!但在iOS4中仍然遇到同樣的問題。
你試過UIViewAnimationOptionAllowUserInteraction作爲動畫選項? –
這工作,謝謝!如果是評論,我可以接受這種答案嗎? – Rajveer
我發佈了它作爲答案 –