0

This is probably something quite basic. I am trying to implement AdWhirl into my app, which I have done successfully for the technical part. When I load my app, the add loads and then slides down from the top to sit at the bottom of the screen. However, when I rotate the device, the advert uses "precise" locations and moves off screen. When the advert reloads (refreshes every 15 seconds) the advert moves up to the bottom of the screen of the landscape window. Again, when rotating back from landscape, the Advert Aligns it's self in the middle of the page vertically (covering content) until a new advert loads. I have attached a number of photos, in a series showing what happens, all in order and taken at least 10 seconds apart (showing test advert of "Hello").

My code from the Implementation file is included at the end of this post - sorry for not using the code format, just didn't want to put spaces in front of the whole block, and I think it's all relatively relevant. It's also available at the paste bin: http://pastebin.com/mzavbj2L

Sam

Sorry - it wouldn't let me upload images. Please send me a PM for images.

Sam Heather
  • 1,493
  • 3
  • 19
  • 42

2 Answers2

0

I recommend handling the rotation in the willRotateToInterfaceOrientation:duration: method or the didRotateFromInterfaceOrientation:method. You will be able to determine what your new orientation is, the new size of your view, and then change the frame of your AdWhirl view to the new location.

After looking a bit closer, however, it looks like you might need to make *adView a variable declared in your .h file so you can access it from the rotation methods.

Once you do that, you can set your new frame as you did in the viewDidLoad: method:

CGSize adSize = [adView actualAdSize];
CGRect newFrame = adView.frame;
newFrame.size = adSize;
newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/ 2;
newFrame.origin.y = (self.view.bounds.size.height - adSize.height);
adView.frame = newFrame;
[UIView commitAnimations];

Ideally, you would move this code into its own method so you can just call it from wherever you want in your view controller code (e.g. viewDidLoad and the rotation function(s)).

joran
  • 169,992
  • 32
  • 429
  • 468
aTotalStranger
  • 318
  • 1
  • 9
  • After changing my header file as seen above, I now get the following error when ever adView is mentioned: local declaration of "adView" hides instance variable. – Sam Heather Oct 19 '11 at 16:44
  • Judging by your .h file, it looks like you are using an AdWhirl view that you have placed in Interface Builder. If that is the case, then you shouldn't redeclare your adView object on line 50 of your .m file. That is, instead of another `AdWhirlView *adView = ...` in your .m, just use `adView=`. I'm not too familiar with AdWhirl's Interface Builder setup, but it might be easier to remove the IB stuff from your code and your XIB and just declare it in code. As an aside, is there a reason there are two AdWhirlView objects in your .h file? – aTotalStranger Oct 20 '11 at 16:16
  • How would I declare *adView as a variable in my .h file? I've tried my method, but now I just get build errors. – Sam Heather Nov 13 '11 at 20:42
  • Sam, I apologize but I had an e-mail glitch and was not notified of your response. You can declare *adView in your header file by putting `AdView *adView;` within the declaration of your interface (in the .h file). Then, in a method called during the setup of your controller, you would say something like `adView = ` however you are declaring it now. – aTotalStranger Dec 22 '11 at 20:02
  • Hi aTotalStranger. Thanks for your help - it was close to a solution (only just got it working tonight - had mostly forgotten about doing it!). After I made you changes to my .h, I was trying to call [adWhirlView adWhirlDidReceiveAd:(AdWhirlView *)adView]. This kept returning errors, even though it was defined in the AdWhirlView class. As a fix, I added -(void) adWhirlDidReceiveAd:(AdWhirlView *)adView and then called each time the frame rotated [self adWhirlDidReceiveAd:(AdWhirlView *)adView]; – Sam Heather Jan 17 '12 at 18:41
0

Thanks for your help - it was close to a solution (only just got it working tonight - had mostly forgotten about doing it!). After I made you changes to my .h, I was trying to call [adWhirlView adWhirlDidReceiveAd:(AdWhirlView *)adView]. This kept returning errors, even though it was defined in the AdWhirlView class. As a fix, I added -(void) adWhirlDidReceiveAd:(AdWhirlView *)adView and then called each time the frame rotated [self adWhirlDidReceiveAd:(AdWhirlView *)adView];.

Thanks again - so glad it's finally working.

Sam

Sam Heather
  • 1,493
  • 3
  • 19
  • 42