![](/img/trans.png)
[英]how to implement AirPrint into an iOS app using swift Xcode 6
[英]AirPrint (UIPrintInteractionController) print warnings with iOS 9, swift 2, XCode 7
自从更新到最新的 XCode/Swift 2/iOS 9 后,我在尝试使用 UIPrintInteractionController 时不断收到警告。
这些警告仅在我打开“打印模拟器”时发生。 我认为这是我的应用程序,所以我使用单个 UIButton 制作了一个新的单视图应用程序,它执行非常简单的代码,但仍然会生成警告。 它发生在手机和 iPad 模拟器上
请帮忙。 快把我逼疯了,谢谢大家
@IBAction func Clicked(sender: AnyObject) {
let printController = UIPrintInteractionController.sharedPrintController()
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfoOutputType.General
printInfo.jobName = "print Job"
printController.printInfo = printInfo
let formatter = UIMarkupTextPrintFormatter(markupText: "<b>Hello World</b>")
formatter.contentInsets = UIEdgeInsets(top: 72, left: 72, bottom: 72, right: 72)
printController.printFormatter = formatter
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
printController.presentAnimated(false, completionHandler: nil)
}else{
printController.presentFromRect(view.frame, inView: view, animated: false, completionHandler: nil)
}
}
以下是警告:
2015-09-29 18:58:19.748 MyApp[1608:527574] Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x13d5c6170>.
2015-09-29 18:58:20.013 MyApp[1608:527574] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-09-29 18:58:20.014 MyApp[1608:527574] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2015-09-29 18:58:20.015 MyApp[1608:527574] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x13d6a1e10>, and it is attached to <UICollectionView: 0x13e063c00; frame = (0 0; 320 250); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13d5e7ef0>; layer = <CALayer: 0x13d507850>; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0x13d6a1e10>.
2015-09-29 18:58:20.015 MyApp[1608:527574] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-09-29 18:58:20.026 MyApp[1608:527574] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-09-29 18:58:20.026 MyApp[1608:527574] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2015-09-29 18:58:20.027 MyApp[1608:527574] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x13d6a1e10>, and it is attached to <UICollectionView: 0x13e063c00; frame = (0 0; 320 250); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13d5e7ef0>; layer = <CALayer: 0x13d507850>; contentOffset: {0, 0}; contentSize: {320, 250}> collection view layout: <UICollectionViewFlowLayout: 0x13d6a1e10>.
2015-09-29 18:58:20.027 MyApp[1608:527574] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-09-29 18:58:21.735 MyApp[1608:527574] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-09-29 18:58:21.735 MyApp[1608:527574] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2015-09-29 18:58:21.736 MyApp[1608:527574] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x13d6ba990>, and it is attached to <UICollectionView: 0x13e02c400; frame = (0 0; 320 250); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13d6809a0>; layer = <CALayer: 0x13d6aa750>; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0x13d6ba990>.
2015-09-29 18:58:21.736 MyApp[1608:527574] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-09-29 18:58:21.758 MyApp[1608:527574] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-09-29 18:58:21.759 MyApp[1608:527574] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2015-09-29 18:58:21.759 MyApp[1608:527574] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x13d6ba990>, and it is attached to <UICollectionView: 0x13e02c400; frame = (0 0; 320 250); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13d6809a0>; layer = <CALayer: 0x13d6aa750>; contentOffset: {0, 0}; contentSize: {320, 250}> collection view layout: <UICollectionViewFlowLayout: 0x13d6ba990>.
2015-09-29 18:58:21.759 MyApp[1608:527574] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
可能问题出在
printController.presentFromRect(view.frame, inView: view, animated: false, completionHandler: nil)
验证presentFromRect
的视图矩形
或者尝试使用
[printController presentAnimated:YES completionHandler:nil];
此解决方案删除了我的代码的警告,试试你的运气。
有同样的问题,通过使用委托方法printInteractionControllerParentViewController(printInteractionController
:) 解决了(感谢 Balooka!)
所以:
在类标题中:
UIPrintInteractionControllerDelegate
某处:
let printController = UIPrintInteractionController.sharedPrintController() printController.delegate = self
实现委托功能:
func printInteractionControllerParentViewController(printInteractionController: UIPrintInteractionController) -> UIViewController { return self }
当UICollectionView
的项目大小不正确时,会打印您问题中提到的警告。 正如消息所述, UICollectionViewCell
高度不能高于UICollectionView
加上部分和内容插入的总和。
我找到了你的问题,因为我遇到了同样的警告并且正在寻找它。 在我的情况下,代码如下所示:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let height = self.collectionView.frame.height
let width = height * 0.75
return CGSizeMake(width, height)
}
行let height = self.collectionView.frame.height
对我造成了警告。 我什至将插图更改为零,但直到我使用let height = self.collectionView.frame.height * 0.75
缩短高度之前,警告并没有消失。
不确定这是否相关,因为您的代码未显示任何 UICollectionView 相关信息,并且插图用于打印控制器。 你看对地方了吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.