问题
如何修改scrollView的滚动目标?我正在寻找一种替代“经典” scrollView委托方法的方法
override func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
......在这里我们可以modfify目标scrollView.contentOffset通过targetContentOffset.pointee例如创建一个自定义分页行为。
或者换句话说:我确实想在(水平)scrollView中创建分页效果。
我尝试过的就是 是这样的:
ScrollView(.horizontal, showsIndicators: true, content: {
HStack(alignment: VerticalAlignment.top, spacing: 0, content: {
card(title: "1")
card(title: "2")
card(title: "3")
card(title: "4")
})
})
// 3.
.content.offset(x: self.dragState.isDragging == true ? self.originalOffset : self.modifiedOffset, y: 0)
// 4.
.animation(self.dragState.isDragging == true ? nil : Animation.spring())
// 5.
.gesture(horizontalDragGest)
Run Code Online (Sandbox Code Playgroud)
尝试
这是我尝试过的方法(除了自定义的scrollView方法):
scrollView的内容区域大于屏幕空间,因此根本无法滚动。
我创建了一个,DragGesture()以检测是否有阻力在继续。在.onChanged和.onEnded闭包中,我修改了@State值以创建所需的scrollTarget。
有条件地将原始未更改的值和新修改的值都馈送到.content.offset(x:y :)修饰符中-取决于dragState作为缺少的scrollDelegate方法的替代。
仅在拖动结束时才有条件地添加动画。
将手势附加到scrollView。
长话短说。没用 我希望我能解决我的问题。
有什么解决办法吗?期待任何投入。谢谢!
我无法从内存中释放我的 RealityKit ARView()。
我知道 ARKit + SceneKit \xe2\x80\x93 存在类似问题,并具有如下解决方法:/sf/answers/3774381131/ \n这确实解决了我的问题不幸的是问题。
\n\n上述解决方案通过手动删除所有“可疑”内容来发挥作用。这正是我在更广泛的范围内所做的:
\n\nclass ViewController_ARViewMemoryTest: UIViewController {\n\n var arView: ARView?\n\n init() {\n super.init(nibName: nil, bundle: nil)\n arView = ARView(frame: .zero)\n }\n\n required init?(coder: NSCoder) {\n fatalError("init(coder:) has not been implemented")\n }\n\n deinit {\n doEverythingThatsNeeded()\n }\n\n public func doEverythingThatsNeeded() {\n self.arView?.session.pause()\n self.arView?.session.delegate = nil\n self.arView?.removeFromSuperview()\n // Quite a few more removals and resets here, ie. for Combines AnyCancellables\n self.arView = nil\n }\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我也从外部调用 doEverythingThatsNeeded() :
\n\naRViewMemoryTest?.doEverythingThatsNeeded()\naRViewMemoryTest?.arView …Run Code Online (Sandbox Code Playgroud) 在全新且非常整洁的情况下UICollectionViewCompositionalLayout- 如何UICollectionViewLayoutAttributes在初始创建时缓存?
所有已知的方法和属性似乎都已内置,因为新的布局类继承自UICollectionViewLayout.
回顾“旧的”自定义UICollectionViewLayout方法,据我所知,此类任务的路径是使用方法prepare()用定制的[UICollectionViewLayoutAttributes].
根据我的理解,新的布局类会逐节创建布局,从我们在 WWDC19 演讲“集合视图布局的进展”-> NSCollectionLayoutSection中看到的方法中返回createLayout(). And it seems to do that only once at initialisation.
现在,我对 a 进行了子类化UICollectionViewCompositionalLayout,并且layoutAttributesForElements该类按预期返回:
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {\n let superAttributes = super.layoutAttributesForElements(in: rect)\n print("I am returning attributes: ", supersAttributes)\n return superAttributes\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但由于它们不是手动创建的,我在哪里可以最初一次性捕获这些属性以添加到缓存数组中?
\n\n这条路径的原因是我试图重新创建一个非常非常高的collectionViewLayout,我需要它可缩放。而这(至少在过去)只能通过使用缓存、在 zion 期间修改缓存属性并layoutAttributesForElements(in: rect)在整个生命周期中从缓存返回来获得性能。\n我在 Ray Wenderlich\xc2\xb4s tuturials …