简体   繁体   中英

iAd not working in iPhone in landscape

I have an app that only runs on iPhone in landscape. I have implemented iAd to put a banner across the bottom of the screen. This worked great when compiled in Xcode 4 but now in Xcode 5 there is a problem. When a user tapped the ad in the old version, the full size ad would load in portrait. But now when a user taps an ad, it loads the ad but only the top half of the screen has the ad - the bottom remains blank. It work correctly in the simulator and on test devices using the "test" ads, but now that the app is live it is broken.

Everything works perfectly on iPad, which is not restricted to landscape only. I have double checked my code and everything is just as the documentation states. Apple has been less than helpful with this. Any thoughts?

在此处输入图片说明

Update: I found 2 more pieces to the puzzle. This only happens with iOS 8. When the user taps the banner ad, I get a "Unable to simultaneously satisfy constraints" error with the following:

"<NSLayoutConstraint:0x7c948310 H:[UIView:0x7c947e80(219)]>",
"<NSLayoutConstraint:0x7c94edf0 H:[UILabel:0x7c94ecb0'Elapsed\n0:00'(62)]>",
"<NSLayoutConstraint:0x7c94f180 H:[UIView:0x7c94a430]-(0)-[UILabel:0x7c94ecb0'Elapsed\n0:00']>",
"<NSLayoutConstraint:0x7c94f210 UIView:0x7c94a430.width == UIView:0x7c94a320.width>",
"<NSLayoutConstraint:0x7c94f270 H:|-(0)-[UIView:0x7c94a430]   (Names: '|':UIView:0x7c9479e0 )>",
"<NSLayoutConstraint:0x7c94f2d0 H:[UILabel:0x7c94ecb0'Elapsed\n0:00']-(-1)-[UIView:0x7c94a320]>",
"<NSLayoutConstraint:0x7c94f390 H:[UIView:0x7c94a320]-(1)-[UIView:0x7c947e80]>",
"<NSLayoutConstraint:0x7c94f3f0 UIView:0x7c9479e0.centerX == UIView:0x7c947e80.centerX>",
"<NSLayoutConstraint:0x7c9504b0 H:|-(0)-[UIView:0x7c9479e0]   (Names: '|':UIView:0x7c94f920 )>",
"<NSLayoutConstraint:0x7c9504e0 H:[UIView:0x7c9479e0]-(0)-|   (Names: '|':UIView:0x7c94f920 )>",
"<NSLayoutConstraint:0x7c971e90 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7c94f920(320)]>"

"Will attempt to recover by breaking constraint "
"<NSLayoutConstraint:0x7c948310 H:[UIView:0x7c947e80(219)]>"

And, the status bar is now covered by my view, whereas in ios7 it is shown. I built the storyboard layout originally for ios7 so something has changed. I don't really care (actually prefer) not having the status bar appear, but I can't figure out how to debug those constraints.

Are you using Storyboards—could there be something there affecting the rotation and sizing? I recommend making a new project with a single blank view controller set up landscape as yours is and trying to reproduce the issue there.

Some things that could be affecting this are:

Often I find that going through the steps to recreate a bug reveals errors, lets me see differences between a working version and mine, and ultimately correct the problem.


I find it easiest to compare these against the ones in a Storyboard. For deciphering them like this refer to the visual format language .

It looks like the constraint ensuring a specific view is horizontally 219 equal to its superview is being broken. Check your storyboard for any auto layout warnings or errors, I have found it immensely helpful in Xcode 6.

You have several constraints, if you can remove some while debugging that can make things much simpler. Lastly if your subviews all reference each other that may make satisfying the constraints more difficult, if that is the case referencing the superview may help prevent conflicts.

Here are some references for debugging:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM