2014-10-05 69 views
1

在我的應用程序中,我在我的主視圖控制器中有兩個視圖。一個是輸入有關您預算的詳細信息。另一個用於查看預算的當前狀態。新屏幕尺寸的動畫視圖問題

當在輸入視圖上輕敲輸入按鈕時,該視圖向下滑動以顯示當前預算視圖。

在viewWillAppear我有一些代碼是執行的,如果輸入按鈕已被點擊,但視圖尚未移動(這發生在應用程序完全關閉並重新打開時)。

重置按鈕與輸入按鈕相反,並將視圖向上滑動。

問題是,有時當點擊重置按鈕時,視圖開始向上滑動,但隨後停在視圖底部附近。在我更新我的應用程序以使用iPhone 6和iPhone 6 Plus之前,這一切都工作得很好,所以我認爲我的座標計算出了問題。我只是無法弄清楚。下面是它的外觀時,它卡住:

enter image description here

復位按鈕:

self.budgetEntryView.hidden = false 
    resetButtonNav.enabled = false 

    UIView.animateWithDuration(0.3, delay: 0, options: .CurveLinear, animations: { 
     self.budgetEntryView.center = CGPointMake(self.budgetEntryView.center.x, self.budgetEntryView.center.y - 500) 
     }, completion: { (finished:Bool) in 
      self.budgetDisplayView.hidden = true 

viewWillAppear中:

 if enterButtonTapped == true && self.budgetEntryView.center.y != 784 { 

     UIView.animateWithDuration(0.3, delay: 0, options: .CurveLinear, animations: { 
      self.budgetEntryView.center = CGPointMake(self.budgetEntryView.center.x, self.budgetEntryView.center.y + 500) 
      }, completion: { (finished:Bool) in self.budgetEntryView.hidden = true }) 
     } 

確認鍵:

 UIView.animateWithDuration(0.3, delay: 0, options: .CurveLinear, animations: { 
     self.budgetEntryView.center = CGPointMake(self.budgetEntryView.center.x, self.budgetEntryView.center.y + 500) 
     }, completion: { (finished:Bool) in self.budgetEntryView.hidden = true }) 
+0

你使用自動佈局?如果是這樣,你可以考慮動畫的約束,而不是視圖的寬度/高度/位置。 – zisoft 2014-10-05 15:50:45

+0

沒有。我嘗試儘早使用自動佈局,但我真的不喜歡它。我將它用於Today Widget,因爲它是一個更簡單的用戶界面,但我想避免將它用於主應用程序。代碼有沒有明顯的錯誤可能會導致您可以看到的問題? – user3746428 2014-10-05 15:53:57

+0

對不起,我看不到明顯的東西。在代碼中放置幾個​​println()語句來檢查中心座標是否發生了變化。並更好地使用'CGPoint(...)'而不是'CGPointMake(...)' – zisoft 2014-10-05 16:01:30

回答

0

釷一旦我按照建議使用println來查找問題,e修復相當簡單。

基本上,我不得不對新屏幕尺寸這樣的添加視圖將定位的座標爲:

if enterButtonTapped == true && self.budgetEntryView.center.y != 784 && self.budgetEntryView.center.y != 868 && self.budgetEntryView.center.y != 740 && self.budgetEntryView.center.y != 833.5 {