以下方法不行UIViewController* controller = self.view.window.rootViewController;
[picker showBoard]; self.modalPresentationStyle = UIModalPresentationCurrentContext; [controller presentViewController:picker animated:YES completion:nil];
认证0级讲师
Adakah anda mahu membuat kotak gesaan pop timbul? Anda boleh menggunakan MBProgressHUD kesan:
Warna dan kandungan boleh disesuaikan. Jika anda mahu ini, saya boleh membuat susulan tentang cara menggunakannya
Kod disalin terus daripada projek:
HomeViewController.swift //点击的事件 @objc private func titleBtnClick(){ //创建弹出控制器 let popVc = PopViewController() //设置控制器的Model样式 popVc.modalPresentationStyle = .Custom //设置转场的代理 popVc.transitioningDelegate = self //弹出控制器 presentViewController(popVc, animated: true, completion: nil) } // MARK: - 自定义转场的代理方法 extension HomeViewController :UIViewControllerTransitioningDelegate { //改变弹出窗口的Frame func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? { return LMSUIPresentationController(presentedViewController: presented, presentingViewController: presenting) }
}
Pengawal timbul:LMSUIPresentationController.m
import UIKit class LMSUIPresentationController: UIPresentationController { private lazy var maskView : UIView = UIView() override func containerViewWillLayoutSubviews() { super.containerViewWillLayoutSubviews() //设置弹出View的尺寸 presentedView()?.frame = CGRectMake(100, 55, 180, 240) //添加蒙版 setUpMask() } } extension LMSUIPresentationController { private func setUpMask() { //添加蒙版 containerView?.insertSubview(maskView, atIndex: 0) //设置蒙版的属性 maskView.backgroundColor = UIColor(white: 0.7, alpha: 0.2) maskView.frame = containerView!.bounds //添加手势 let tapGes = UITapGestureRecognizer(target: self, action: "maskViewClick") maskView.addGestureRecognizer(tapGes) } } extension LMSUIPresentationController { @objc private func maskViewClick() { presentedViewController.dismissViewControllerAnimated(true, completion: nil) } }
PopViewController.swift
import UIKit class PopViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.redColor() } } 运行出来的效果类似于sinaWeibo首页顶部点击昵称的效果
Adakah anda mahu membuat kotak gesaan pop timbul? Anda boleh menggunakan MBProgressHUD
kesan:
Warna dan kandungan boleh disesuaikan.
Jika anda mahu ini, saya boleh membuat susulan tentang cara menggunakannya
Kod disalin terus daripada projek:
}
Pengawal timbul:
LMSUIPresentationController.m
PopViewController.swift