Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

ios - UINavigationController更改高度时会切断内容吗? (gif)(UINavigationController cuts off content when height is changed? (gif))

I have put a UINavigationController into an expandable "Drawer".

(我已将UINavigationController放入可扩展的“抽屉”中。)

My goal is to let each viewController in the navigation stack to have its own "preferred" height.

(我的目标是让导航堆栈中的每个viewController具有其自己的“首选”高度。)

Let's say VC1 needs to be tall.

(假设VC1需要很高。)

When navigating back to VC1 from VC2 I want it to animate its height to be tall.

(从VC2导航回VC1时,我希望它动画化其高度。)

The animation logic seems to be working, even with the interaction of swipe.

(即使进行滑动交互,动画逻辑似乎也可以正常工作。)

But for some reason, the viewControllers in the navigationController are "cut off".

(但是由于某种原因,navigationController中的viewController被“切断”了。)

Their constraints are correct, but they aren't updated(?).

(它们的约束是正确的,但是没有更新(?)。)

Or a portion of the content simply won't render, until I touch the view again.

(否则部分内容将无法渲染,直到再次触摸视图。)

The invisible area on the bottom will even accept touches.

(底部的不可见区域甚至可以接受触摸。)

Take a look:

(看一看:)

gif

The expected result is that the contentViewControllers (first and second) always extend to the bottom of the screen.

(预期结果是contentViewControllers(第一和第二个)始终延伸到屏幕的底部。)

They are constraint to do this, so the issue is that they won't "render"(?) during the transition.

(它们是这样做的约束,所以问题在于它们在过渡期间不会“渲染”(?)。)

In the UINavigationController's delegates, I do the following:

(在UINavigationController的委托中,我执行以下操作:)

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
    transitionCoordinator?.animate(alongsideTransition: { (context) in
            drawer.heightConstraint.constant = targetHeight
            drawer.superview?.layoutIfNeeded()
        }, completion: { (context) in
            print("done")
        })
}

The height change is perfect.

(高度变化是完美的。)

But the content in the navigation won't comply.

(但是导航中的内容不符合要求。)

The navigationController is constrained to leading, trailing, bottom, and a stored heightConstraint that changes its constant.

(navigationController限制为前导,尾随,底部和已存储的heightConstraint,它们会更改其常数。)

As soon as I touch/drag the navigationController/content it instantly "renders the unrendered", and everything is fine.

(一旦我触摸/拖动navigationController /内容,它就会立即“渲染未渲染的内容”,一切都很好。)

Why is this happening?

(为什么会这样呢?)

When inspecting the view hierarchy, it looks like this:

(检查视图层次结构时,它看起来像这样:)

在此处输入图片说明

The NavigationController is as tall as it needs to be, but the content is the same height as the entire Drawer was when the transition started, and it doesn't update until I touch it.

(NavigationController足够高,但是内容与过渡开始时整个Drawer的高度相同,并且直到我触摸它才会更新。)

Why?

(为什么?)

  ask by Sti translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...