2015-06-30 46 views

回答

0

你可以做的一件事!!!添加視圖的姿態背後的觀點,這種觀點應該相同的姿勢查看(甚至應該有相同的文字),以及識別手勢之後一度帶來-前的這一觀點你的姿勢查看它應該有舊的文本(不更新文本)和更新的姿態視圖的文字的人它移動後面新增的觀點,只是改變新添加視圖的框架,以便它給出了一個滑動樣的效果(改變其寬度)在完成動畫之後將該視圖帶回到手勢視圖並將其框架更改爲之前的先前值。

檢查此示例:

func handleGesture(sender:UISwipeGestureRecognizer) { 
    //bring background view to front 
    self.view.bringSubviewToFront(self.backGroundView) 
    self.gestureView.userInteractionEnabled = false 

    //capture its initialAutolayout constraint 
    let backgroundViewSpaceConstarint = self.backGroundViewLeftSpaceConstraint.constant 
    UIView.animateWithDuration(2, animations: { [unowned self]() -> Void in 
     self.someRandomValue++ 

     // update text label in gesture view which is behind background View 
     self.gestureViewTextLabel.text = "swiped \(self.someRandomValue) times" 

     //slide backgroundView in required direction by using autolayout 
     self.backGroundViewLeftSpaceConstraint.constant = self.backGroundView.bounds.size.width 
     self.backGroundView.layoutIfNeeded() 
     }) { [unowned self](completion:Bool) -> Void in 
      //after animation complition bring gesture view to the front. 
      self.backgroundTextLabel.text = "swiped \(self.someRandomValue) times" 
      self.gestureView.userInteractionEnabled = true 

      //upadte background view so that it will look the same for next swipe 
      self.backGroundViewLeftSpaceConstraint.constant = backgroundViewSpaceConstarint 
      //send the background view behind gesture view 
      self.view.sendSubviewToBack(self.backGroundView) 
      } 
    }