2016-06-20 42 views
0

我是一名初學者,最近我開始製作動畫,我的目標是iPhone 6s plus。它的所有關於移動某些Ÿ點球到另一..動畫約束快速適合所有屏幕

func animateBall(){ 
     UIView.animateWithDuration(0.5, delay: 0.0000001, options : [.CurveEaseInOut, .TransitionCurlDown,] , animations: { 

     self.ball1.frame.origin.y = 121.0 
     self.ball2.frame.origin.y = 175.0 
     self.ball3.frame.origin.y = 340.0 
     self.ball4.frame.origin.y = 394.0 
     self.ball5.frame.origin.y = 447.0 
     self.ball6.frame.origin.y = 502.0 
     self.ball7.frame.origin.y = 555.0 
     self.ball8.frame.origin.y = 585.0 
     self.ball9.frame.origin.y = 68.0 

     // 
     //   } 
     // 

     } ,completion :{(finished:Bool) in 
      // the code you put here will be compiled once the animation finishes 
      self.restoreToNormalBalls() 


    }) 
} 



func restoreToNormalBalls(){ 

    self.ball1.frame.origin.y = 68 
    self.ball2.frame.origin.y = 121 
    self.ball3.frame.origin.y = 175 
    self.ball4.frame.origin.y = 340 
    self.ball5.frame.origin.y = 394 
    self.ball6.frame.origin.y = 447 
    self.ball7.frame.origin.y = 502 
    self.ball8.frame.origin.y = 555 
    self.ball9.frame.origin.y = 15 

} 

我已經做了限制,以適應在所有屏幕上,但是當我點擊動畫,它僅適用於6S加。任何幫助都可以使動畫在所有屏幕上都可以使 感謝

+2

如果您使用自動佈局,您應該動畫,而不是框架 – lubilis

+0

約束常數謝謝您的回覆:),如何從點動畫約束常量任一實例另一個? –

回答

0

如果您使用自動佈局,您應該動畫約束常量,而不是框架:

func animateBall() { 

    ball1Constraint.constant = 121.0; 
    ball2Constraint.constant = 175.0; 

    UIView.animateWithDuration(0.5, delay: 0.0000001, options : [.CurveEaseInOut, .TransitionCurlDown,] , animations: { 

     self.view.layoutIfNeeded() // called on parent view 

    } ,completion :{ (finished:Bool) in 

     // the code you put here will be compiled once the animation finishes 
     self.restoreToNormalBalls() // remember to modify this implementation method using constraints too 
    }) 
} 
  • ball1Constraint & ball2Constraint是約束conn ected爲@IBOutlet從情節提要/ XIB文件
1

至於建議的@lubilis,

首先添加約束從球上邊緣上方的空間是容器視圖。
然後將該約束條件設置爲@IBOutlet,比如說outletedConstraintBall1
然後同時動畫,不喜歡:

UIView.animateWithDuration(0.5, delay: 0.0000001, options : [.CurveEaseInOut, .TransitionCurlDown,] , animations: { 

    outletedConstraintBall1.constant = 121 
    containerView.layoutIfNeeded() 
}) 

而復位它的位置:

restoreToNormalBalls() { 
    outletedConstraintBall1.constant = 68 
}