gpt4 book ai didi

ios - viewController.view 不显示,但在 ViewDebugMode 时出现

转载 作者:搜寻专家 更新时间:2023-10-31 22:36:42 25 4
gpt4 key购买 nike

我正在使用 PanGestureaddChild 创建幻灯片菜单。

虽然 ParentViewController 可以向左滑动,但是放在它右边的 MenuViewController 没有显示。

但是,当您使用 ViewDebug 检查时,它确实存在并且放置在预期的位置。

但是为什么它没有显示在实际屏幕上呢?

👇 当 View 被平移时 enter image description here

👇 当查看调试并点击此按钮时 enter image description here enter image description here

class ParentViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.isUserInteractionEnabled = true
view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(panGesturePanned)))

let menuViewController = MenuViewController()
menuViewController.view.frame = CGRect(
x: view.frame.maxX,
y: 0,
width: view.bounds.width,
height: UIScreen.main.bounds.height)
view.addSubview(menuViewController.view)
addChild(menuViewController)
menuViewController.didMove(toParent: self)
}

@objc private func panGesturePanned(gesture: UIPanGestureRecognizer) {
guard let gestureView = gesture.view else { return }

switch gesture.state {
case .began:
print()
case .changed:
tabBarController?.view.frame.origin.x = min(max(gesture.translation(in: gestureView).x, -240), 0)

case .cancelled:
print()

case .ended:
print()

default: break
}
}
}

最佳答案

您正在移动 tabBarController,但据我了解您想要移动 menuViewController。试试这个:

@objc private func panGesturePanned(gesture: UIPanGestureRecognizer) {
guard let gestureView = gesture.view else { return }

switch gesture.state {
case .began: break
case .changed:
tabBarController?.view.frame.origin.x = max(-menuViewController.view.bounds.width, gesture.translation(in: gestureView).x)
menuViewController.view.frame.origin.x = max(0, menuViewController.view.bounds.width - gesture.translation(in: gestureView).x)
case .cancelled: break
case .ended: break
default: break
}
}

关于ios - viewController.view 不显示,但在 ViewDebugMode 时出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57755722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com