2014-11-22 102 views
1

我正在嘗試製作一個動畫,以便將Y軸向上移動約50個點。 該動畫有效,但一旦完成,它將返回到其原始位置。iOS:動畫視圖移回到原始位置

UIView* view = [self.view viewWithTag:50]; 
    [UIView animateWithDuration:0.5 
          delay:0.1 
         options: UIViewAnimationOptionCurveEaseOut 
        animations:^ 
    { 
     CGRect frame = view.frame; 
     frame.origin.y = 230; 
     frame.origin.x = 30; 
     view.frame = frame; 
    } 
        completion:^(BOOL finished) 
    { 
     NSLog(@"Completed"); 

    }]; 

回答

1

您的佈局約束將拉回來。這是目前很常見的問題。你必須修改你的NSLayoutConstraint對象來反映對視圖的改變。

E.g. Constraint.constant + = 50;

搜索堆棧溢出的其他問題,如你想問之前問。

+0

哎呀,我所有的谷歌搜索使我對過時的答案。我知道它的工作。謝謝! – Andy 2014-11-22 20:09:41

0

對於完整性,約束需要在動畫改變和更新,如下圖所示:

- (IBAction)moveAction:(id)sender { 
    self.spaceConstraint.constant += 220; 

    [UIView animateWithDuration:0.5 animations:^{ 
     [self.imageView layoutIfNeeded]; 
    }]; 
} 
相關問題