作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我做了以下事情:1.拖拽UIView放置在ViewController功能区
导入 UIKit
类 EditProfileView:UIView {
let globalDataHandler = GlobalDataHandler.sharedInstance
@IBOutlet weak var firstNameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var userNameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBAction func saveEditButton(sender: AnyObject) {
}
@IBAction func cancelEditButton(sender: AnyObject) {
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
将“EditProfileView”类作为Storyboard 中“Edit Profile View” View 的自定义类。
在 ProfileViewController 中为“EditProfileView”类创建了一个对象,并将“Edit Profile View” View 添加到主视图点击 ProfileViewController 中的编辑按钮。
类 ProfileViewController: UIViewController {
let profileView = EditProfileView()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func editProfileButton(sender: AnyObject) {
profileView.firstNameTextField.text = "First Name"
profileView.lastNameTextField.text = "Last Name"
profileView.userNameTextField.text = "User Name"
profileView.emailTextField.text = "Email"
let testFrame : CGRect = CGRectMake(50,100,300,300)
profileView.frame = testFrame
self.view.addSubview(profileView)
}
但是,“编辑配置文件 View ” View 不会出现在 ProfileViewController 上。请帮忙。
最佳答案
您必须在 Xib 中链接您的 UIView 和您的 View (应该是一个不同的 UIViewController)。
profileView = storyboard.instantiateViewControllerWithIdentifier("ProfileViewController")
您的 ProfileVC 必须有一个 UIPresentationController
class ProfilePresentationController : UIPresentationController {
override func frameOfPresentedViewInContainerView() -> CGRect {
return CGRect(x: (presentingViewController.view.frame.width / 2.0) - 150.0, y: (presentingViewController.view.frame.height / 2.0) - 100.0, width: 300.0, height: 200.0)
}
}
您的 EditProfileView 必须实现以下委托(delegate):
UIViewControllerTransitioningDelegate
您的 profileView 的以下属性也必须设置为:
profileView.modalPresentationStyle = UIModalPresentationStyle.Custom
profileView.transitioningDelegate = self
之后你可以实现委托(delegate)所需的方法
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return ProfilePresentationController(presentedViewController: presented, presentingViewController: presenting)
}
关于iphone - 如何将 Storyboard中创建的 UIView 添加为 Swift 中的弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38207929/
我是一名优秀的程序员,十分优秀!