gpt4 book ai didi

ios - swift : show another view controller on swipe up in first view controller

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

您好,我检查了很多关于在 SO 中刷卡的问题,但有疑问。

在我的应用程序中,我有两个页面1.用户 View Controller 2.问题 View Controller

用户页面是这样的 userpage

现在我想要实现的是在从底部向上滑动用户屏幕时显示问题 View Controller 。

我是 Ios 的新手,请帮助我实现这一目标。

编辑:

问题是向上滑动时它应该开始显示另一个 View Controller 。如果我滑动到屏幕中间,手指仍然触摸屏幕,那么它应该显示 2 个 View Controller 。我可以像这样使用 push/pop 来实现吗

enter image description here

最佳答案

您可以使用自动布局和滑动手势来实现这一点。棘手的部分是为您的 View 设置约束。向您的 View 添加一个负高度常量约束,使其不显示在 View 中。

@IBOutlet weak var yourViewBottomConstraint: NSLayoutConstraint! //Create IBOutlet of bottom Contraint to YourView

let swipeUp = UISwipeGestureRecognizer() // Swipe Up gesture recognizer
let swipeDown = UISwipeGestureRecognizer() // Swipe Down gesture recognizer OR You can use single Swipe Gesture

比你的 viewDidLoad()

Override func viewDidLoad() {
// Swipe Gesture
swipeUp.direction = UISwipeGestureRecognizerDirection.up
swipeUp.addTarget(self, action: "swipedViewUp")
drawerButton.addGestureRecognizer(swipeUp) // Or assign to view

swipeDown.direction = UISwipeGestureRecognizerDirection.down
swipeDown.addTarget(self, action: "swipedViewDown")
drawerButton.addGestureRecognizer(swipeDown) // Or assign to view
}

滑动 View 的方法

 // Toggle Swipe Action for imagesContainer
func swipedViewUp(){

self.yourViewBottomConstraint.constant = +90 // Or set whatever value

print("Swiped Up")
}

func swipedViewDown(){

self.yourViewBottomConstraint.constant = -90 // Or Set whatever value


print("Swiped Down")
}

关于ios - swift : show another view controller on swipe up in first view controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35035047/

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