提取childView并将其重新放置在新的parentView中

问题描述 投票:0回答:2

我正在尝试从滚动视图中嵌入的stackView中提取视图,然后将所述视图重新放置在与scrollView相同的位置,但在视图层次结构中处于相同级别的另一个视图中。

我试图实现的效果是,我正在动画化视图的移除,即该视图将被叠加在另一个视图中,而scrollView将向上滚动并将新视图添加到stackView中,被撕开的视图逐渐消失。

[不幸的是,由于rippedView处于(x:0,y:0),实现这种效果仍然遥不可及。当我尝试将新帧强加到该视图上时,它很困难,因为我猜测像素完美正确。这是我的viewController的一些代码:

/* 
 I tried to make insertionView and imposeView have the same dimensions as the scrollView and 
 the stackView respectively as I thought if the rippedView’s original superView is the same 
 dimensions as it’s new superView, the rippedView would be positioned in the same place 
 without me needing to alter its frame.
 */


let insertionView = UIView(frame: scrollView.frame)
let imposeView = UIView(frame: stackView.frame) 

rippedView.removeFromSuperview()
insertionView.addSubview(imposeView)
imposeView.addSubview(rippedView)

let newFrame = CGRect(x: 0, y: 450, width: rippedView.intrinsicContentSize.width, height: 
rippedView.intrinsicContentSize.height)

rippedView.frame = newFrame
self.view.addSubview(insertionView)
ios swift uiview frame bounds
2个回答
0
投票

[Before


0
投票
您遇到的问题很可能是由于stackView的已安排子视图将.translatesAutoresizingMaskIntoConstraints设置为false。我相信将视图添加到stackView时会自动发生,除非另行指定。
© www.soinside.com 2019 - 2024. All rights reserved.