Change UIButton alpha from different class - iphone

Hey guys!
I want to change the alpha of a UIButton which sounds actually pretty simple. However, I want to change that alpha from a different class(ViewControllerB.m/.h). I got a class called "ViewController.h/.m" and from this class I call a view which appears on the ViewController like a popup. Now I got a UIButton which displays the popup, when it's touched. If the button was touched its alpha will change to "0.0" and the popup will be shown. I got the code from the popup in another class and I want to change the alpha of the button to "1.0" if the pupup was dismissed. I already got a method, that is called when the popup was dismissed. I tried everything, but it didn't worked so far. Maybe because I'm a beginner at iOS ^^.
I hope you understood what I am trying to say. I will leave the code as it is (clean) to do not confuse you with the ways I tried before.
Here you got the codes of my classes:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
//....
IBOutlet UIButton *myBtn;
//...
}
- (IBAction)OpenPopUp:(id)sender;
Now in my ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
//...viewDidLoad....everything else
- (IBAction)OpenPopUp:(id)sender {
[UIView animateWithDuration: 1.0
animations:^{
myBtn.alpha = 0.0;
}];
}
#end
In my ViewControllerB.h:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#interface ViewControllerB : UIViewController {
//...some unneccesary outlets
}
//Displaying popup.....
- (void)presentInParentViewController:(UIViewController *)parentViewController;
#end
ViewControllerB.m :
#import "ViewControllerB.h"
#interface ViewControllerB ()
#end
#implementation
//...ViewDidload...and more
- (IBAction)close:(id)sender {
//The close button
[self dismissFromParentViewController];
}
- (void)dismissFromParentViewController {
//Removes the nutrition view from the superview
[self willMoveToParentViewController:nil];
//Removes the view with or without animation
if (!self.shouldAnimateOnDisappear) {
[self.view removeFromSuperview];
[backgroundGradientView removeFromSuperview];
[self removeFromParentViewController];
return;
}
else {
[UIView animateWithDuration:0.4 animations:^ {
CGRect rect = self.view.bounds;
rect.origin.y += rect.size.height;
self.view.frame = rect;
backgroundGradientView.alpha = 0.0f;
}
completion:^(BOOL finished) {
[self.view removeFromSuperview];
[backgroundGradientView removeFromSuperview];
[self removeFromParentViewController];
}];
}
//THE PLACE I WANT TO CHANGE THE ALPHA BACK!
}
I really would appreciate anyones help and if you can please show it me on code examples.
Thank you,
Noah
NOTE: I already looked up this posts but tried unsuccsessfully.
Passing Data between View Controllers
Passing data between view controllers in IOS
Modifying UIButton's alpha property from another class
Change alpha and enabled UIButton of ClassA from ClassB in object c

There are 2 ways of doing it,
In ViewController *viewDidAppear:* method check myBtn alpha. if alpha is zero then set the alpha back to 1.
You can add ViewController as a delegate in ViewControllerB and ViewControllerB notifies ViewController when it is dismissed and then you set the alpha of myBtn back to 1
In my ViewControllerB.h:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#protocol ViewControllerBDelegate <NSObject>
- (void)didHidePopoverController
#end
#interface ViewControllerB : UIViewController {
//...some unneccesary outlets
}
#property(readwrite,weak)id <ViewControllerBDelegate>delegate;
//Displaying popup.....
- (void)presentInParentViewController:(UIViewController *)parentViewController;
#end
ViewController.h
#import <UIKit/UIKit.h>
#import "ViewControllerB.h"
#interface ViewController : UIViewController<ViewControllerBDelegate> {
//....
IBOutlet UIButton *myBtn;
//...
}
- (IBAction)OpenPopUp:(id)sender;
#end
Now in ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
//...viewDidLoad....everything else
- (IBAction)OpenPopUp:(id)sender {
[UIView animateWithDuration: 1.0
animations:^{
myBtn.alpha = 0.0;
}];
}
- (void)didHidePopoverController {
[UIView animateWithDuration: 1.0
animations:^{
myBtn.alpha = 1.0;
}];
}
#end
ViewControllerB.m :
#import "ViewControllerB.h"
#interface ViewControllerB ()
#end
#implementation
//...ViewDidload...and more
- (IBAction)close:(id)sender {
//The close button
[self dismissFromParentViewController];
}
- (void)dismissFromParentViewController {
//Removes the nutrition view from the superview
[self willMoveToParentViewController:nil];
//Removes the view with or without animation
if (!self.shouldAnimateOnDisappear) {
[self.view removeFromSuperview];
[backgroundGradientView removeFromSuperview];
[self removeFromParentViewController];
return;
}
else {
[UIView animateWithDuration:0.4 animations:^ {
CGRect rect = self.view.bounds;
rect.origin.y += rect.size.height;
self.view.frame = rect;
backgroundGradientView.alpha = 0.0f;
}
completion:^(BOOL finished) {
[self.view removeFromSuperview];
[backgroundGradientView removeFromSuperview];
[self removeFromParentViewController];
}];
}
[self.delegate didHidePopoverController];
//THE PLACE I WANT TO CHANGE THE ALPHA BACK!
}
When you are showing the popup just assign ViewController instance as a delegate of ViewControllerB instance

Update: I seached for it and found it. The awser from Anshul Join didn't worked for me but what worked for me was this: Update a label through button from different view
It is much less complicated and easy to implement. There are no delegates. Hope I could help anyone with this.
But summed up: Thanks to Anshul Jain for supporting me and trying to solve this for me. Thank you bro!

Related

iAd in sprite kit game

I know there is at least one question asking how to integrate iAd into a sprite kit game, but that is not what I am looking for. I am looking for a portrait version of how to do it. There seem to be absolutely 0 tutorials online as to how to do this, so I came here. Can someone please tell me how to simply enable iAd in a Sprite Kit game? I have enabled canDisplayBannerAds and have used the originalContentView property for my UIView, but I keep getting a crash that says
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController originalContentView]: unrecognized selector sent to instance 0x10a0a7410'
any help would be appreciated, and here is my code in my view controller
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.originalContentView;
//skView.showsFPS = YES;
//skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
self.canDisplayBannerAds = YES;
// Present the scene.
[skView presentScene:scene];
}
For those that don't understand, and those that are for future references, here is how I did this to my Sprite Kit game.
I had my game project created using the SpriteKit template in Xcode, then went to the project settings as so:
In the "Link Binary With Libraries" section, just make sure to hit the + button, and add the iAd framework.
After doing that, go to your view controller for your Sprite Kit game, and then type this:
// at the top
#import <iAd/iAd.h>
// do this in .m, above #implementation
#interface YourViewControllerClassName ()
#property (nonatomic, strong) ADBannerView *banner;
#end
// after the implementation line
// if you're needing to do it horizontally, do:
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.banner = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.banner.delegate = self;
[self.banner sizeToFit];
self.canDisplayBannerAds = YES;
SKView *view = (SKView *)self.originalContentView;
SKScene *scene = [[YourScene alloc] initWithSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
[view presentScene:scene];
}
If you're doing the iAd in just a normal, portrait, you can do the above code, but you can also just use - (void) viewDidLoad instead...
Now is the delegate methods for the iAd to appear...
Go to the code above the #implementation line, and edit it
// do this in .m, above #implementation
#interface YourViewControllerClassName () <ADBannerViewDelegate>
#property (nonatomic, strong) ADBannerView *banner;
#end
Now, go under the implementation line, and enter this:
// NOTE: THIS CODE CAME FROM APPLE MOSTLY
// I DID EDIT IT, BUT THE CREDIT GOES TO APPLE'S DOCUMENTATION
// ON IAD
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (banner.isBannerLoaded) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!banner.isBannerLoaded) {
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
}
}
That is all that is required from the iAd to actually work in a SpriteKit game. I hope that I helped those that are going to read this.

Flip view like now playing in iTunes?

I have an app in progress that has a lot of views for various purposes. Within one of them, I'd like to use an existing View as the 'background', and then have a view inserted within that flips - very similar to the "Now Playing" view on an iPhone/iPod where the album cover flips between the image and the track listings.
Can someone point me in the right direction?
Take a look at Apples View Controller Programming Guide for iOS. I guess the easiest way would be using a modal view with UIModalTransitionStyleFlipHorizontal set as transition style (look for "Presenting a View Controller and Choosing a Transition Style" on the guide I posted.).
Tutorials:
- http://timneill.net/2010/09/modal-view-controller-example-part-1/
- http://timneill.net/2010/11/modal-view-controller-example-part-2/
EDIT
I guess you're using a UINavigationController, so here's an example ViewController, which keeps the navigation bar visible. Just put a second view inside your view controller and hide it. Than implement a method (I used an IBAction, which I hook to a button using InterfaceBuilder), which switches between these views:
ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
UIView *backSideView;
}
- (IBAction)switchViews:(id)sender;
#end
ViewController.h:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
backSideView = [[UIView alloc] initWithFrame:[self view].bounds];
[backSideView setBackgroundColor:[UIColor greenColor]];
// ... put stuff you want inside backSideView ...
[backSideView setHidden:YES];
[[self view] addSubview:backSideView];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)switchViews:(id)sender
{
if ( [backSideView isHidden] )
{
[UIView transitionWithView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [backSideView setHidden:NO]; }
completion:^(BOOL finished){ [self setTitle:#"BackView"]; }
];
}
else
{
[UIView transitionWithView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{ [backSideView setHidden:YES]; }
completion:^(BOOL finished){ [self setTitle:#"FrontView"]; }
];
}
}
#end

is it a good practice to delete the AdBannerView on viewWillDisappear and add it back on viewWillAppear?

I am currently doing the following in my code avoid the issue of "obscured" ad. But is it a good practice? One potential problem is that - assume before the viewWillDisappear, there was an ad request send out, and then when the ad come back the adBannerView instance has gone. Would that be a big problem? Should I only do hideAdBanner instead?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
// create the ad banner view
[self createAdBannerView];
if (adBannerView != nil) {
UIInterfaceOrientation orientation = self.interfaceOrientation;
[self changeBannerOrientation:orientation];
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// iAd
if (adBannerView != nil) {
[self hideAdBanner];
adBannerView.delegate = nil;
[adBannerView release];
adBannerView = nil;
}
}
I use a singleton for an ad banner and call it into view on each ViewDidLoad. This automatically removes it from the previous view.
This is for adWhirl, but you should be able to adopt it for just iAD.
adWhirlSingleton.h
#import <Foundation/Foundation.h>
#import "AdWhirlDelegateProtocol.h"
#import "AdWhirlView.h"
#interface adWhirlSingleton : NSObject <AdWhirlDelegate> {
AdWhirlView *awView;
UIViewController *displayVC;
}
#property (strong, nonatomic) AdWhirlView *awView;
#property (strong, nonatomic) UIViewController *displayVC;
+(id)sharedAdSingleton;
-(void)adjustAdSize:(CGFloat)x:(CGFloat)y;
#end
adWhirlSingleton.m
#import "adWhirlSingleton.h"
#implementation adWhirlSingleton
static adWhirlSingleton* _sharedAdSingleton = nil;
#synthesize awView, displayVC;
+(id)sharedAdSingleton
{
#synchronized(self)
{
if(!_sharedAdSingleton)
_sharedAdSingleton = [[self alloc] init];
return _sharedAdSingleton;
}
return nil;
}
+(id)alloc
{
#synchronized([adWhirlSingleton class])
{
NSAssert(_sharedAdSingleton == nil, #"Attempted to allocate a second instance of a singleton.");
_sharedAdSingleton = [super alloc];
return _sharedAdSingleton;
}
return nil;
}
-(id)init
{
self = [super init];
if (self != nil) {
// initialize stuff here
self.awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
}
return self;
}
-(void)dealloc
{
displayVC = nil;
if (awView) {
[awView removeFromSuperview]; //Remove ad view from superview
[awView replaceBannerViewWith:nil];
[awView ignoreNewAdRequests]; // Tell adwhirl to stop requesting ads
[awView setDelegate:nil];
awView = nil;
}
}
-(void)adjustAdSize:(CGFloat)x :(CGFloat)y
{
[UIView beginAnimations:#"AdResize" context:nil];
[UIView setAnimationDuration:0.7];
awView.frame = CGRectMake(x, y, kAdWhirlViewWidth, kAdWhirlViewHeight);
[UIView commitAnimations];
NSLog(#"Recent Network Name: %#",[awView mostRecentNetworkName]);
}
-(BOOL)adWhirlTestMode
{
return YES;
}
-(NSString *)adWhirlApplicationKey
{
return #"xxxxxxxxxxxxx";
}
-(UIViewController *)viewControllerForPresentingModalView
{
return displayVC;
}
-(void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView
{
NSLog(#"%s",__FUNCTION__);
NSLog(#"Recent Network Name: %#",[awView mostRecentNetworkName]);
//[self adjustAdSize];
}
-(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo
{
NSLog(#"%s",__FUNCTION__);
}
#end
Then import adWhirlSingleton into each ViewController and in each viewWillAppear i just implement this:
adWhirlSingleton *adWhirlSingle = [adWhirlSingleton sharedAdSingleton];
adWhirlSingle.displayVC = self;
[adWhirlSingle adjustAdSize:0 :self.view.frame.size.height -50];
[self.view addSubview:adWhirlSingle.awView];
[self.view bringSubviewToFront:adWhirlSingle.awView];
NSLog(#"Ad Banner View");
but the view I have with a UITableView, I use this:
adWhirlSingleton *adWhirlSingle = [adWhirlSingleton sharedAdSingleton];
adWhirlSingle.displayVC = self;
[adWhirlSingle adjustAdSize:0 :self.tabBarController.view.frame.size.height -99];
[self.tabBarController.view addSubview:adWhirlSingle.awView];
NSLog(#"Should have added Ad!");
Hope that helps you a bit
Out of interest, why is that you are removing the ADBannerView?
Apple state that you should share the ADBannerView instances across views.
From the docs: "If your application has multiple tabs or views displaying an iAd banner, be sure to share a single instance of ADBannerView across each view."
i.e. Apple think you should have the ADBannerView presented at the top/front of your view hierarchy and just move it off-screen when there is no ad to show.
So, to answer the question, "is it bad practice to remove and then add it again?"
yes, Apple would say it is.

AdBannerView shared across multiple views, including the rootviewcontroller, how?

No answers yet, but i've got an update that seems to have fixed the problem, any ideas why it works now though?!
I've got it to work in the way I intended by doing the following to every class that needs to display an adBanner:
1. In the layoutForCurrentOrientation method I added the following:
adBanner.delegate = self;
[self.view addSubview:adBanner];
2. In the deAlloc method on each class, I removed the following:
[adBanner removeFromSuperview];
Original question:
I'm attempting to use the iAdSuite sample code from Apple to use a single adBanner instance shared across all my views.
The sample implementation is designed to show the adbanner on each view that is called by the rootViewController, however, I would like my app to have ads on the rootViewController view also.
In my amended code:-
When I fire up the app, no banner is shown on the rootView, even though a method is called to request an ad banner. The class is set as the delegate for the ad and the delegate methods are available. These are called and the log for (adBanner.bannerLoaded) is NO.
As it is a shared object, if I switch views to from the rootView the ad is displayed in the other view.
When I return back to the rootView, the delegate method log shows that a banner is loaded, and it is positioned in a visible portion of the view. But the banner isn't visible.
In summary, i'm using the iAdSuite sample code for the AdBannerNavigation project, and trying to use it so that ad banners show on all views, including the rootViewController.
Any help appreciated!
The code i'm using is available here:
http://developer.apple.com/library/ios/#samplecode/iAdSuite/Introduction/Intro.html
My amended rootViewController.h:
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#interface RootViewController : UITableViewController <ADBannerViewDelegate>
#end
My amended rootViewController.m
#import "RootViewController.h"
#import "TextViewController.h"
#import "MapViewController.h"
#import "AdBannerNavigationAppDelegate.h"
// for SharedAdBannerView macro
// #define SharedAdBannerView ((AdBannerNavigationAppDelegate *)[[UIApplication sharedApplication] delegate]).adBanner
#import <iAd/iAd.h>
#interface RootViewController()
// Layout the Ad Banner and Content View to match the current orientation.
// The ADBannerView always animates its changes, so generally you should
// pass YES for animated, but it makes sense to pass NO in certain circumstances
// such as inside of -viewDidLoad.
- (void)layoutForCurrentOrientation:(BOOL)animated;
// A simple method that creates an ADBannerView
// Useful if you need to create the banner view in code
// such as when designing a universal binary for iPad
- (void)createADBannerView;
#end
- (void)viewDidLoad
{
[super viewDidLoad];
[self createADBannerView];
[self layoutForCurrentOrientation:NO];
}
- (void)viewDidUnload
{
ADBannerView *adBanner = SharedAdBannerView;
adBanner.delegate = nil;
[adBanner removeFromSuperview];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self layoutForCurrentOrientation:NO];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self layoutForCurrentOrientation:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)dealloc
{
ADBannerView *adBanner = SharedAdBannerView;
adBanner.delegate = nil;
[adBanner removeFromSuperview];
[super dealloc];
}
- (void)createADBannerView
{
ADBannerView *adBanner = SharedAdBannerView;
NSString *contentSize;
if (&ADBannerContentSizeIdentifierPortrait != nil)
{
contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierLandscape;
}
else
{
contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifier320x50 : ADBannerContentSizeIdentifier480x32;
}
CGRect frame;
frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSize];
frame.origin = CGPointMake(0.0f, CGRectGetMaxY(self.view.bounds));
adBanner.frame = frame;
adBanner.delegate = self;
adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
adBanner.requiredContentSizeIdentifiers =
(&ADBannerContentSizeIdentifierPortrait != nil) ?
[NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil] :
[NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil];
[self.view addSubview:adBanner];
}
- (void)layoutForCurrentOrientation:(BOOL)animated
{
ADBannerView *adBanner = SharedAdBannerView;
CGFloat animationDuration = animated ? 0.2f : 0.0f;
CGRect contentFrame = self.view.bounds;
CGPoint bannerOrigin = CGPointMake(CGRectGetMinX(contentFrame), CGRectGetMaxY(contentFrame));
CGFloat bannerHeight = 0.0f;
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierLandscape != nil) ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifier480x32;
else
adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierPortrait != nil) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifier320x50;
bannerHeight = adBanner.bounds.size.height;
if (adBanner.bannerLoaded)
{
contentFrame.size.height -= bannerHeight;
bannerOrigin.y -= bannerHeight;
}
else
{
bannerOrigin.y += bannerHeight;
}
[UIView animateWithDuration:animationDuration
animations:^{
adBanner.frame = CGRectMake(bannerOrigin.x, bannerOrigin.y, adBanner.frame.size.width, adBanner.frame.size.height);
}];
NSLog(#"%f is y pos, height=%f, is it loaded...%#", adBanner.frame.origin.y, adBanner.frame.size.height, adBanner.bannerLoaded?#"YES":#"NO");
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[self layoutForCurrentOrientation:YES];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[self layoutForCurrentOrientation:YES];
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
return YES;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
}
#end

How to know when a view is displayed? - Using Burstly for Ad integration

I am trying to use Burstly to serve iAds and adMob ads into my iPhone app. I followed their guide
http://docs.burstly.com/guides/ad-serving-quick-start-guide.html
Here's a snippet of what I have...
MyViewController.h
#interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, OAIAdManagerDelegate> {
OAIAdManager *adManager;
IBOutlet UIView *mainView;
}
#property (nonatomic, retain) UIView *mainView;
#end
MyViewController.m
#import "MyViewController.h"
#implementation MyViewController
#synthesize mainView;
- (void)viewDidLoad {
[super viewDidLoad];
adManager = [[OAIAdManager alloc] initWithDelegate:self];
[self.view addSubview:adManager.view];
[adManager requestRefreshAd];
}
- (UIViewController *)viewControllerForModalPresentation {
return self;
}
- (CGFloat)defaultSessionLife {
return 35.0f;
}
- (Anchor)anchor {
return Anchor_Bottom;
}
- (CGPoint)anchorPoint {
return CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height);
}
- (NSString *)publisherId {
return #"ENTER YOUR PUBLISHER ID HERE";
}
- (NSString *)getZone {
return #"ENTER YOUR ZONE ID HERE";
}
- (UIViewController *)viewControllerForModalPresentation {
return self;
}
// resize mainView (pull up) when ad is displayed
- (void)adManager:(OAIAdManager*)manager didLoad:(NSString*)aNetwork {
[UIView beginAnimations:#"AdResize" context:nil];
[UIView setAnimationDuration:0.7];
CGRect mainViewNewFrame = mainView.frame;
mainViewNewFrame.size.height = 460 - adSize;
mainViewNewFrame.size.width = 320;
mainViewNewFrame.origin.x = 0;
mainViewNewFrame.origin.y = 0;
mainView.frame = mainViewNewFrame;
[UIView commitAnimations];
}
// resize MainView when ad is not available
- (void)adManager:(OAIAdManager*)manager failedToLoad:(NSString*)aNetwork {
[UIView beginAnimations:#"AdResize" context:nil];
[UIView setAnimationDuration:0.7];
CGRect mainViewNewFrame = mainView.frame;
mainViewNewFrame.size.height = 460;
mainViewNewFrame.size.width = 320;
mainViewNewFrame.origin.x = 0;
mainViewNewFrame.origin.y = 0;
mainView.frame = mainViewNewFrame;
[UIView commitAnimations];
}
I'm having issues knowning exactly when an ad is being displayed so that I can know to rearrange my view. I have a table view touching the bottom of the screen, so I need to pull it up (resize my the view) when an ad is displayed.
I tried using the OAIAdManagerDelegateProtocol "adManager:didLoad:" method, which gives mixed results. That method is always called when the admanager thinks it has an ad, but sometimes an ad is not displayed (especially the first call for an iAd). So, I'm always resizing my main view to make room for an ad when that method is called, but sometimes an ad is not there to be displayed, so I end up showing a white space the size of the ad.
I also tried using the "adManager:didLoadView:" method, but it is never called.
So, is there any other way to be notified when the adManager.view is shown on screen so I can know when to resize my view?
this is Alex with Burstly. This was in fact an issue with our code and iOS 4.1. We've resolved it and you can find an updated SDK on github: http://github.com/burstly/Burstly-iPhone/downloads