swift:在第一个视图控制器中向上滑动显示另一个视图控制器 [英] swift : show another view controller on swipe up in first view controller

查看:206
本文介绍了swift:在第一个视图控制器中向上滑动显示另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi I checked many questions regarding swiping in SO but have doubts .

在我的应用程序中我有两页
1.用户视图控制器
2.问题视图控制器

In my app I have two pages 1. user view controller 2. question view controller

用户页面看起来像这样

user page looks like this

现在我要实现的是在从底部向上滑动用户屏幕时显示问题视图控制器。

now what i want to implement is to show questions view controller while swiping up the users screen from bottom.

我是Ios的新手,所以请帮帮我实现这一点。

I am new to Ios, so help me in achieving this.

编辑:

edit:

问题在于只刷它应该开始显示另一个视图控制器。如果我用手指仍然触摸屏幕直到屏幕中间滑动,那么它应该显示2个视图控制器。我用这样的推/弹来实现这个

the problem is while swiping up only it should start showing the other view controller. if i swiped till middle of the screen with my finger still touching the screen, then it should show 2 view controllers.can I achieve this using push/pop like this

< a href =https://i.stack.imgur.com/6PtTH.jpg =nofollow noreferrer>

推荐答案

您可以使用自动布局和滑动手势来实现此目的。棘手的部分是为您的视图设置约束。在视图中添加一个高度常数约束的负数,以便它不会显示在视图中。

You can achieve this using Auto-layout and Swipe Gesture. Tricky part is setting constraints to your view. Add a negative of height constant constraint to your view so that it does not show in 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()

Than in your 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
}

和滑动视图的方法

 // 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")
}

这篇关于swift:在第一个视图控制器中向上滑动显示另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆