AirPrint(UIPrintInteractionController)使用iOS 9,swift 2,XCode 7打印警告

时间:2015-09-30 00:09:32

标签: swift ios9 airprint uiprintinteractioncntrler

自从更新到最新的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.

3 个答案:

答案 0 :(得分:1)

可能问题在于

printController.presentFromRect(view.frame, inView: view, animated: false, completionHandler: nil)

验证presentFromRect

的视图rect

或者尝试

[printController presentAnimated:YES completionHandler:nil];

此解决方案删除了​​我的代码警告,试试运气。

答案 1 :(得分:1)

有同样的问题,使用委托方法printInteractionControllerParentViewController(printInteractionController :)解决了 (感谢Balooka!)

所以:

  1. 在课程标题中:

    UIPrintInteractionControllerDelegate
    
  2. 某处:

    let printController = UIPrintInteractionController.sharedPrintController()
    
    printController.delegate = self
    
  3. 实施委托功能:

    func printInteractionControllerParentViewController(printInteractionController: UIPrintInteractionController) -> UIViewController {
        return self
    }
    

答案 2 :(得分:0)

当项目的大小在UICollectionView内时,会打印出问题中提到的警告。正如消息所述,UICollectionViewCell的高度不能高于UICollectionView加上部分&amp;的总和。内容插入。

我达成了你的问题,因为我遇到了同样的警告,正在寻找它。在我的例子中,代码如下所示:

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相关的信息,并且插件用于打印控制器。你在寻找合适的地方吗?