从底部滑入 UIView [英] Sliding-In UIView From Bottom

查看:26
本文介绍了从底部滑入 UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个具有自定义外观的操作表.我认为最简单的方法是将视图创建为子视图并将子视图顶部的约束分配给超级视图的底部.并同时分配具有一些不透明度的封面视图.因此,我可以有不同版本的子视图,我可以初始化必要的一个并滑动它.

我找不到任何对 Swift 有用的东西,因此,使用

如何使用我作为子视图创建的 UIView(在 Storyboard 中),然后调整其宽度约束,以便 UI 不会出错?另外,如何应用过渡动画使其看起来自然?

第 2 步:将此视图的背景颜色设置为黑色,不透明度为 62%,Alpha = 1

第 3 步:采用新的简单 UIView 并设计您的实际视图并设置约束.

对于Exp:

在您的情况下,在底部设置视图.第 4 步:在视图控制器中加载 xib.

class calendarViewController: UIViewController{var popUpView:popUpView!覆盖 func viewDidLoad() {super.viewDidLoad()bookingConfirmView = NSBundle.mainBundle().loadNibNamed("popUpView", owner: self, options: nil).first as!弹出式视图//为 xib textField 设置委托self.popUpView.Name.delegate = selfself.popUpView.MobileNo.delegate = self}}

第 5 步:

将此行添加到要填充视图的位置.

self.view.addSubview(bookingConfirmView)self.bookingConfirmView.frame = self.view.bounds

I am trying to build a custom-looking action sheet. I thought the easiest way would be creating a view as a subview and assign constraint of subview's top to superview's bottom. And at the same time assigning a cover view with some opacity. Thus, I could have different versions of subview and I can initialise the necessary one and slide it.

I couldn't find anything useful for Swift, so, using this obj-c answer, I tried to convert it to Swift. I achieved the opaque background with this however translating constraints doesn't seem to work.

 var coverView = UIView()

override func viewDidLoad() {
    super.viewDidLoad()

    coverView.backgroundColor = UIColor(white: 0.0, alpha: 0.4)
    coverView.alpha = 1.0
    self.view.addSubview(coverView)
    self.view.bringSubviewToFront(coverView)
} 

//doesn't work
 self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[coverView]|", options: kNilOptions, metrics: nil, views: NSDictionaryOfVariableBindings(coverView)))
 self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[coverView]|", options: kNilOptions, metrics: nil, views: NSDictionaryOfVariableBindings(coverView)))

I got confused on instantiating the view and applying transition animation. If I choose to create a UIView under ViewController, I cannot adjust constraints to adjust equal width of subview to superview.

How can I use the UIView that I created as a Subview (in Storyboard) and then adjust its width constraints so the UI doesn't bug? Also, how can I apply the transition animation so it seems natural?

This link should be here...

解决方案

I suggested you use UIView xib file and design your view then load in your view controller.

Ex:

Step 1:

Create xib for view

Step 2: Set background color black for this view, opacity 62% and Alpha = 1

Step 3: Take new simple UIView and Design your actual view and set constraint.

For Exp:

In your case set view in bottom. Step 4: Load xib in view controller.

class calendarViewController: UIViewController
{
    var popUpView: popUpView!
    override func viewDidLoad() {
       super.viewDidLoad()
       bookingConfirmView = NSBundle.mainBundle().loadNibNamed("popUpView", owner: self, options: nil).first as! popUpView
    // Set Delegate for xib textField
    self.popUpView.Name.delegate = self
    self.popUpView.MobileNo.delegate = self
    }
}

Step 5:

Add this line to where you want to populate view.

self.view.addSubview(bookingConfirmView)
self.bookingConfirmView.frame = self.view.bounds

这篇关于从底部滑入 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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