我對我的UIView
動畫有惱人的問題。基本上我通過跟隨手指位置來做一個UIView旋轉動畫。當視圖完全加載時,一切正常,但如果用戶在從我的Web服務傳入新數據(視圖內容)時拖動手指,則視圖從屏幕跳出。當用戶滾動一下時,視圖跳回到它的位置,一切都很好。那麼我能做些什麼來防止這種跳躍。UIPangesture <--> UIView動畫故障
我認爲傳入的數據觸發類似layoutIfNeeded
,這會影響動畫位置。 另一個想法是它與我的autoLayout約束衝突。
動畫像這樣做:
- (IBAction)handlePan:(UIPanGestureRecognizer *)gesture {
UIView *currentView = self.viewToAnimate;
CGPoint translation = [gesture translationInView:gesture.view.superview];
CGFloat percent = translation.x/gesture.view.bounds.size.width;
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0/-800;
currentView.layer.transform =
CATransform3DRotate(transform, M_PI * percent, 0.0, 1.0, 0.0);
//Snap back if the users lifts his finger
if (gesture.state == UIGestureRecognizerStateEnded ||
gesture.state == UIGestureRecognizerStateCancelled ||
gesture.state == UIGestureRecognizerStateFailed) {
[UIView animateWithDuration:0.45
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ currentView.transform = CGAffineTransformIdentity; }
completion:nil];
}
}
你可以嘗試停止視圖上的動畫,以防他們是罪魁禍首。你可以用'[currentView.layer removeAllAnimations]'來做到這一點。 –