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
Related
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!
This question is very similar to an existing question asked here UIImagePickerControllerCameraDeviceFront only works every other time I tried the solution presented but it didn't work for me
I have a simplest of a project with two view controllers. In the blue one I am displaying a small UIView with a UIImagePickerController in it. NOTE: I am displaying front facing camera when app is launched.
I hit the next button and go to orange view controller and when I hit the back button and come back to blue view controller the UIImagePickerController flips from Front to rear. I guess the reason is that it thinks its busy and moves to the rear cam. If I keep moving back and forth between the view controllers the camera keeps flipping front, back, front, back, front, back...
Here is my code and screenshots, what am I doing wrong?
In my *.h
#import <UIKit/UIKit.h>
#interface v1ViewController : UIViewController <UIImagePickerControllerDelegate>
{
UIImagePickerController *picpicker;
UIView *controllerView;
}
#property (nonatomic, retain) UIImagePickerController *picpicker;
#property (nonatomic, retain) UIView *controllerView;
#end
In my *.m file (This code is only used when blue colored view controller is displayed)
#import "v1ViewController.h"
#import <MobileCoreServices/UTCoreTypes.h>
#implementation v1ViewController
#synthesize picpicker;
#synthesize controllerView;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
picpicker = [[UIImagePickerController alloc] init];
picpicker.delegate = self;
picpicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
picpicker.sourceType = UIImagePickerControllerSourceTypeCamera;
picpicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picpicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picpicker.showsCameraControls = NO;
picpicker.navigationBarHidden = NO;
picpicker.wantsFullScreenLayout = NO;
controllerView = picpicker.view;
[controllerView setFrame:CGRectMake(35, 31, 250, 250)];
controllerView.alpha = 0.0;
controllerView.transform = CGAffineTransformMakeScale(1.0, 1.0);
[self.view addSubview:controllerView];
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
controllerView.alpha = 1.0;
}
completion:nil
];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[picpicker dismissModalViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[picpicker dismissModalViewControllerAnimated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#end
You are dismissing the controller in both the viewDidDisappear and viewWillDisappear methods.
That could be the cause of your problem.
Although I do not have a device with a camera available right now to verify this, it seems that you're not dismissing the pickerview controller correctly. The documentation states that you should call dismissModalViewControllerAnimated: on the parent controller in order to dismiss the picker (though, calls to presented controllers will propagate to presenters - so this is not the problem), but in your case you're not displaying the controller modally in the first place so it will not work.
What I would try in this case is to release the picker instead (if not under ARC) and set it to nil (instead of calling [picpicker dismissModalViewControllerAnimated:YES];).
PS. In fact, it seems that there is a bigger problem with your design. Since each button is set to present the other party modally you are not dismissing any of the controllers ever. The controllers just keep stacking on each other. You should either consider to embed them in a navigation controller and have it handle the hierarchy or just set dismissModalViewControllerAnimated: (dismissViewControllerAnimated:completion: on iOS5+) as the action of the second controller's button instead of a modal segue.
This is a very simple issue. I don't know why this happens exactly, but it seems that UIImagePickerController was designed to recreated each time it's needed instead of keeping any reference to it, which seems logical if you think about it. Basically, you need to recreate and reconfigure your picker each time. Below I've pasted some code to give an image of what I mean.
Simple solution:
- (UIImagePickerController *)loadImagePicker {
UIImagePickerController *picpicker = [[UIImagePickerController alloc] init];
picpicker.delegate = self;
picpicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
picpicker.sourceType = UIImagePickerControllerSourceTypeCamera;
picpicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picpicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picpicker.showsCameraControls = NO;
picpicker.navigationBarHidden = NO;
picpicker.wantsFullScreenLayout = NO;
return picpicker;
}
and in:
-(void)viewWillAppear:(BOOL)animated{
if(!self.picpicker){
self.picpicker = [self loadImagePicker];
[self.view addSubview: self.picpicker];
}
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.picpicker removeFromSuperview];
self.picpicker = nil;
}
My app must NOT auto-rotate at all. But it includes a screen which tells the user to rotate his phone (and not the opposite!).
To do that, the ViewController must make an animated rotation (without any rotation event) when the screen is displaying.
So I used
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:animated];
[super viewWillDisappear:animated];
}
And
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
to make my screen rotate, as every website and documentation recommend.
But only the StatusBar rotates: my NavigationBar remains stuck at the top.
I would use a CGAffineTransform perhaps on the navigationcontroller view? Simply rotate it using an animation block 90 degrees?
this code is helpful for you to resize the navigation bar automatically you can use it in where you create the navigationController & navigation bar
self.navigationController.navigationBar.autoresizesSubviews = YES;
self.navigationController.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
above code will work automatically if it is not then you try this will work in all delegates methods of your view controller where you need the change
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:animated];
[self.navigationController shouldAutorotateToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation];
}
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
CGRect frame = self.navViewController.navigationBar.frame;
frame.size = self.view.frame.size;
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
frame.size.height = 44;
} else {
frame.size.height = 32;
}
self.navViewController.navigationBar.frame = frame;
if navigation controller is rootview controller then check it enables the all orientation supports
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
[super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
[self.navigationController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
return YES;
}
you can use this code in viewcontroller delegates listed below according to your requirment
- (void)viewDidAppear:(BOOL)animated
- (void)viewWillAppear:(BOOL)animated
– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:
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
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