CGAffineTransformInvert: singular matrix Error

André picture André · Sep 14, 2014 · Viewed 15.7k times · Source

I created Universal App (single view) in Xcode. Because I want to have iAd banner on every view I added this code to AppDelegate file:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
    if var root = self.window?.rootViewController
    {
        let contentFrame = UIScreen.mainScreen().bounds
         var _banner = ADBannerView(adType: ADAdType.Banner)

        _banner.frame=CGRectMake(0, contentFrame.height - _banner.frame.height, _banner.frame.width, _banner.frame.height)
        _banner.delegate = self
        root.view.addSubview(_banner)
    }

    return true
}

On real iPhone (iOS 8) Everything works fine (banner appears on every view) but I'm getting this error:

<Error>: CGAffineTransformInvert: singular matrix.

If i try to run this app on Simulator (iOS 8) the behavior is the same. Everything works fine, i get the same error but moreover i get: *ADBannerView:

 Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:):
 Error Domain=ADErrorDomain Code=7 "The operation couldn’t be completed. Ad was unloaded from 
this banner" UserInfo=0x7b83bf30 {ADInternalErrorCode=7, ADInternalErrorDomain=ADErrorDomain, 
NSLocalizedFailureReason=Ad was unloaded from this banner}*

But I have delegate and I implemented didFailToReceiveAdWithError. On real iPhone it works...

My question is how could I solve these two particular errors?

Answer

Rob Napier picture Rob Napier · Sep 15, 2014

The most likely cause is that one of the rects here is zero. You can't invert a zero matrix (which is a technical detail, and you really shouldn't have to care about; I'm just trying to say why that's the error you get).

application(didFinishLaunchingWithOptions:) is called very early, and the frames probably aren't set yet. You probably want to be doing this work in the viewDidLoad (possibly fixing up the frames in viewWillAppear if necessary) of your root view controller (you probably will need to create a subclass for that if you don't already have one).