、ユーザーがそれに入ると、私はインクルードは、ユーザーが初めてアプリを入力したときにのみ-Ie 1回発生ダッシュボードの上にあまりにも多くのアニメーションを持っている -なぜアニメーションでself.view.layoutIfNeeded()を使用するとアプリがフリーズするのですか?私のアプリで
私はこの方法のようにアニメーションを実行しますこれです使用するコードより明確にするために、別のアニメーション機能を呼び出すコールupperViewAnimation()
機能でviewDidAppear中:
func upperViewAnimation() { contianerTop.constant = 0 UIView.animateWithDuration(0.45, animations: {() -> Void in self.view.layoutIfNeeded() }, completion:{(finished) in if finished { if noInternetConnection && !noInternetConnectionPopup { self.noConnectionViewHeight.constant = 50 UIView.animateWithDuration(0.3, animations: { self.view.layoutIfNeeded() }) noInternetConnectionPopup = true openNoInternetConnection() } else if noInternetConnection { self.noConnectionViewHeight.constant = 50 UIView.animateWithDuration(0.3, animations: { self.view.layoutIfNeeded() }) } else { self.noConnectionViewHeight.constant = 0 UIView.animateWithDuration(0.3, animations: { self.view.layoutIfNeeded() }, completion: { (finished) in self.pullToRefreshAction() }) } self.notificationButtonAnimationAndMenuButton() self.moreAppsLabel.hidden = false } }) } func pullToRefreshAction() { pullToRefreshContainsFailure = false addBlurToCellDelegate?.removeBlurFromAllCells() if firstAppear || userLoggedIn { self.firstAppear = false userLoggedIn = false loadingView2.removeFromSuperview() sucessView.removeFromSuperview() var viewHeight:CGFloat = 50 if isiPadFlag { viewHeight = 60 } loadingView2 = NSBundle.mainBundle().loadNibNamed("GettingDataView", owner: self, options: nil)[0] as! GettingDataView loadingView2.frame = CGRect(x: 0, y: 0, width: screenWidth, height: viewHeight) self.noConnectionView.addSubview(loadingView2) loadingView2.initView() gettingDataForFirstTime = true if showPullToRefreshBool { self.noConnectionViewHeight.constant = 50 } UIView.animateWithDuration(0.3, animations: { self.view.layoutIfNeeded() }) } else { self.noConnectionViewHeight.constant = 0 } } if !gettingData { // I called requests to get data } }
私は私のアプリが時々フリーズ前のコードを実行し、レイアウトが変更されませんようです
(つまり、アプリケーションがUIをレンダリングしないと思われる)self.view.layoutIfNeeded()が多すぎるとこの問題が発生するのでしょうか?
本当に私は
おかげで、
助けてください、この奇妙な問題をあきらめ。
viewDidLayoutSubviewsが必要です。 99%の確率でレイアウトをトリガーする何かをそこで実行しているので、無限ループで実行されます。簡単にチェックできます。そこにprintステートメントを置き、複数回印刷するかどうかを確認してください。 –
@JoshHomannジョシュねえ、あなたの助け、私はviewDidLayoutSubviewsのいずれかの重要なことをしませんでしたactullayためのおかげで、これはそれに私のコードです:オーバーライドFUNCのviewDidLayoutSubviews(){ infoButtoniPad.highlighted = MainDashboardState.InfoStatus settingsButtoniPad.highlighted =あなたの答えのためのMainDashboardState.SettingStatus profileButtoniPad.highlighted = MainDashboardState.ProfileStatus dashboardButtoniPad.highlighted = MainDashboardState.DashboardStatus openGreenPointFromDashboard = falseを } – Rawan