自定义模式对话框
来源:互联网 发布:软件项目估计方法 编辑:程序博客网 时间:2024/06/18 04:01
首先在故事板中拖入一个UIViewController,设计你的UI。我们以下面的例子为例:
在这个ViewController中,上半部分我们将设置为透明(通过代码设置),而下半部分是3个UIButton。
在Identity面板中,将Class 设置为一个新的UIViewController子类。然后创建这个UIViewController子类。
在故事板中,选中3个按钮所在的父UIView,即上图中的containerView,添加如下布局约束:
打开助手编辑器,为最下面一个约束Bottom Space to在创建IBOutlet menuBottomConstraint。
并在viewDidLoad方法中,加入代码:
self.view.backgroundColor = UIColor(white: 0.3, alpha: 0.3)
menuBottomConstraint.constant = -128
在viewDidAppear方法中:
super.viewDidAppear(animated)
self.view.layoutIfNeeded()
UIView.animateWithDuration(0.2) {
self.menuBottomConstraint.constant = 0
self.view.layoutIfNeeded()
}
然后在故事板中,在需要显示这个对话框的Scene中,创建一个segue导航到这个我们的自定义对话框。选择segue,在属性面板中进行如下设置(注意,Animates设置为false,Presentation和Transition要设置为Default,否则背景不会透明):
在需要显示对话框的ViewController的prepareForSegue方法中:
if segue.identifier == “ContactUsController” {
if let vc=segue.destinationViewController as? UIViewController{
vc.modalPresentationStyle =
UIModalPresentationStyle.OverCurrentContext;
}
}
运行程序,效果如下:
- 弹出自定义模式对话框
- 自定义模式对话框
- 自定义的(WEB)模式对话框,
- 常用对话框、自定义对话框
- 对话框之自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- 自定义对话框
- Remix OS——一个很有魅力的Android系统
- 3GPP TS 24.301 V12.4.0 中文版---5.1&5.2&5.3
- debian 163源
- Virtualbox WDDM 用户模式显示驱动之OpenAdapter
- 找出字符串最长不重复子串,输出长度
- 自定义模式对话框
- Python--函数return后面的语句不执行
- PHP 常用设计模式 总结
- 项目汇报XMind 6来帮您
- 由TNS: 无法解析指定的连接标识符引发的追溯
- 英文论文中常见拉丁语/英语缩写整理
- WPF模拟键盘输入相关问题
- Android之路-启程2:Android开发环境简介以及编写第一个应用程序“HelloWorld”
- VS2013运行时提醒签名错误