Swift 3 - 从不调用 adaptivePresentationStyle
Swift 3 - adaptivePresentationStyle is never called
我正在尝试在 iPhone 中显示弹出窗口。我遵循我在此处找到的建议并使用委托 "adaptivePresentationStyle",但从未调用此函数,并且 ViewController 它将始终以全屏模式显示。我有 "UIPopoverPresentationControllerDelegate" 和以下功能:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let identifier = segue.destination.restorationIdentifier ?? ""
if identifier == "NavigationSetup" {
if let destinationNav = segue.destination as? UINavigationController {
let destination = destinationNav.topViewController as! SetupTableViewController
destination.popoverPresentationController?.delegate = self
destination.popoverPresentationController?.backgroundColor = UIColor.blue
if self.myApp.isIpad{
destination.preferredContentSize = CGSize(width: 600, height: 620)
}else{
destination.preferredContentSize = CGSize(width: 0.8 * self.view.frame.size.width, height: 0.8 * self.view.frame.size.height)
}
self.cellAnimations.fade(image: self.imageBlur, initOpacity: 0, endOpacity: 1, time: 0.3, completion: nil)
destination.setupDismiss = {[weak self] () in
if let weakSelf = self{
weakSelf.cellAnimations.fade(image: weakSelf.imageBlur, initOpacity: 1, endOpacity: 0, time: 0.3, completion: nil)
}
}
}
}
}
func adaptivePresentationStyle(for controller:UIPresentationController) -> UIModalPresentationStyle {
print("adaptive was called")
return .none
}
那么,我在这里缺少什么?
可能是你没表现好
let vc = UIViewController()
vc.modalPresentationStyle = .custom;
vc.transitioningDelegate = self;
self.present(vc, animated: true, completion: nil)
使用自定义模态演示文稿进行演示并在演示时制作动画应该可以解决问题
首先,设置断点以确保调用此行:
destination.popoverPresentationController?.delegate = self
更好的是,这样重写,并设置断点以确保调用了内线:
if let pop = destination.popoverPresentationController {
pop.delegate = self
}
如果是,那就太好了!在那种情况下,问题可能是实施了错误的委托方法。你想要这个:
func adaptivePresentationStyle(for controller: UIPresentationController,
traitCollection: UITraitCollection) -> UIModalPresentationStyle {
我正在尝试在 iPhone 中显示弹出窗口。我遵循我在此处找到的建议并使用委托 "adaptivePresentationStyle",但从未调用此函数,并且 ViewController 它将始终以全屏模式显示。我有 "UIPopoverPresentationControllerDelegate" 和以下功能:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let identifier = segue.destination.restorationIdentifier ?? ""
if identifier == "NavigationSetup" {
if let destinationNav = segue.destination as? UINavigationController {
let destination = destinationNav.topViewController as! SetupTableViewController
destination.popoverPresentationController?.delegate = self
destination.popoverPresentationController?.backgroundColor = UIColor.blue
if self.myApp.isIpad{
destination.preferredContentSize = CGSize(width: 600, height: 620)
}else{
destination.preferredContentSize = CGSize(width: 0.8 * self.view.frame.size.width, height: 0.8 * self.view.frame.size.height)
}
self.cellAnimations.fade(image: self.imageBlur, initOpacity: 0, endOpacity: 1, time: 0.3, completion: nil)
destination.setupDismiss = {[weak self] () in
if let weakSelf = self{
weakSelf.cellAnimations.fade(image: weakSelf.imageBlur, initOpacity: 1, endOpacity: 0, time: 0.3, completion: nil)
}
}
}
}
}
func adaptivePresentationStyle(for controller:UIPresentationController) -> UIModalPresentationStyle {
print("adaptive was called")
return .none
}
那么,我在这里缺少什么?
可能是你没表现好
let vc = UIViewController()
vc.modalPresentationStyle = .custom;
vc.transitioningDelegate = self;
self.present(vc, animated: true, completion: nil)
使用自定义模态演示文稿进行演示并在演示时制作动画应该可以解决问题
首先,设置断点以确保调用此行:
destination.popoverPresentationController?.delegate = self
更好的是,这样重写,并设置断点以确保调用了内线:
if let pop = destination.popoverPresentationController {
pop.delegate = self
}
如果是,那就太好了!在那种情况下,问题可能是实施了错误的委托方法。你想要这个:
func adaptivePresentationStyle(for controller: UIPresentationController,
traitCollection: UITraitCollection) -> UIModalPresentationStyle {