Permalink
Browse files

First fully working version!

  • Loading branch information...
1 parent 2c829d2 commit 2f9cd80d725741d0e115113b636434f0c77ed1ee @p-i- committed Apr 3, 2011
View
39 Classes/AppDelegate.m
@@ -20,47 +20,22 @@ - (BOOL) application: (UIApplication *) application
NSLog(@"--> ___PROJECTNAME___AppDelegate:didFinishLaunchingWithOptions...");
// FIXED: now entry in info.plist hides SB BEFORE launch
- [[UIApplication sharedApplication] setStatusBarHidden:(SHOW_SB ? NO : YES)];
+ [[UIApplication sharedApplication] setStatusBarHidden: (SHOW_SB ? NO : YES)];
CGRect appFrame = [UIScreen mainScreen].applicationFrame;
// windowRect must start at 0, 0
// if (SHOW_SB == YES), appFrame will be '{{0, 20}, {320, 460}}'
CGRect windowRect = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height);
-
- //NSLog(@" * windowRect:'%@'", NSStringFromCGRect(windowRect) );
-
+
self.window = [[[UIWindow alloc] initWithFrame: windowRect] autorelease];
-
- //NSLog(@" * window.bounds:'%@'", NSStringFromCGRect(window.bounds) );
-
-
- /* NOTE: init_withFrame lets the view controller know the dimensions of the view it must create.
- it will create the view when loadView is triggered. This will occur automatically the first time
- viewController.view is accessed. ie in [window addSubview:viewController.view]; below */
- self.viewController = [ [ [ ___PROJECTNAME___ViewController alloc ] init /*_withFrame: appFrame*/ ] autorelease ];
-
- /* viewController.view: If you access this property and its value is currently nil,
- the view controller automatically calls the loadView method.
- The default loadView method attempts to load the view from the nib file
- associated with the view controller (if any). If your view controller does
- not have an associated nib file, you should override the loadView
- method and use it to create the root view and all of its subviews. */
-
- // so can't do this:
- //NSLog(@" * viewController.view.bounds:'%@'",
- // NSStringFromCGRect(viewController.view.bounds) );
- // or LoadView then viewDidLoad would get triggered
-
- [window setRootViewController: viewController];
+
+ self.viewController = [ [ [ ___PROJECTNAME___ViewController alloc ] init ] autorelease ];
+
+ [self.window setRootViewController: viewController];
-
- // accessing a nil viewController.view forces loadView then viewDidLoad to be called
- //
- // [window addSubview:viewController.view];
-
// triggers loadView
- [window makeKeyAndVisible];
+ [self.window makeKeyAndVisible];
return YES;
}
View
204 Classes/iAdVC.m
@@ -9,30 +9,41 @@
#import "iAdVC.h"
#import "Settings.h"
+#import "MyView.h"
+
// = = = = = = = = = = = = = = = = = = = = = = = = = =
+#pragma mark PRIVATE INTERFACE
@interface iAdVC ()
@property (retain) UIView * uberView;
@property (retain) ADBannerView * adBannerView;
- - (ADBannerView *) makeAdBanner;
+ @property (retain) UIView * contentView;
+
++ (NSString *) bannerTokenForOrientation: (UIInterfaceOrientation) ori ;
++ (CGSize) bannerSizeForOrientation: (UIInterfaceOrientation) ori ;
@end
// = = = = = = = = = = = = = = = = = = = = = = = = = =
+#pragma mark IMPLEMENTATION
@implementation iAdVC
// - - - - - - - - - - - - - - - - - - - - - - - - - -
@synthesize uberView, adBannerView;
+@synthesize contentView;
-// - - - - - - - - - - - - - - - - - - - - - - - - - -
+// = = = = = = = = = = = = = = = = = = = = = = = = = =
- (UIView *) makeViewUsingFrame: (CGRect) viewFrame
{
- return nil;
+ NSLog(@"OVERRIDE ME!!!");
+ //MyView * v = [[[MyView alloc] initWithFrame: viewFrame] autorelease];
+
+ return nil; //(UIView *) v;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -42,6 +53,10 @@ - (void) loadView
self.uberView = [[[UIView alloc] initWithFrame: [UIScreen mainScreen].applicationFrame] autorelease];
self.uberView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.uberView.autoresizesSubviews = YES;
+
+ // UIKit bug: need this
+ self.uberView.backgroundColor = [UIColor blackColor];
+
[self setView: uberView];
showingBanner = NO;
@@ -51,76 +66,189 @@ - (void) loadView
NSString * P = ADBannerContentSizeIdentifierPortrait;
NSString * L = ADBannerContentSizeIdentifierLandscape;
- adBannerView = [[[ADBannerView alloc] initWithFrame:CGRectZero] autorelease];
+ self.adBannerView = [[[ADBannerView alloc] initWithFrame:CGRectZero] autorelease];
+
+ self.adBannerView.delegate = self;
+ self.adBannerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
+ self.adBannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects: P, L, nil];
- adBannerView.delegate = self;
- adBannerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
- adBannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects: P, L, nil];
- adBannerView.currentContentSizeIdentifier = UIInterfaceOrientationIsPortrait( self.interfaceOrientation ) ? P : L ;
+ // Apps always start in Portrait, then rotate as necessary
+ self.adBannerView.currentContentSizeIdentifier = P;
+ self.adBannerView.hidden = YES;
[uberView addSubview: adBannerView];
}
-}
+
+
+ self.contentView = [self makeViewUsingFrame: uberView.frame];
+
+ NSLog(@"%@", self.contentView);
-// - - - - - - - - - - - - - - - - - - - - - - - - - -
+ self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+
+ [uberView addSubview: contentView];
+
+}
-#pragma mark Autorotate
+// = = = = = = = = = = = = = = = = = = = = = = = = = =
+#pragma mark etc
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
- return YES;
+ return YES; // support all orientations
}
// - - - - - - - - - - - - - - - - - - - - - - - - - -
-- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) newOrientation
- duration: (NSTimeInterval) duration
+-(BOOL) bannerViewActionShouldBegin: (ADBannerView *) banner
+ willLeaveApplication: (BOOL) willLeave
{
- bool isLandscape = UIInterfaceOrientationIsLandscape(newOrientation);
- self.adBannerView.currentContentSizeIdentifier = isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait ;
+ return YES; // allow execution
}
+// - - - - - - - - - - - - - - - - - - - - - - - - - -
+
++ (NSString *) bannerTokenForOrientation: (UIInterfaceOrientation) ori
+{
+ NSString * P = ADBannerContentSizeIdentifierPortrait;
+ NSString * L = ADBannerContentSizeIdentifierLandscape;
+
+ return UIInterfaceOrientationIsPortrait( ori ) ? P : L ;
+}
-#pragma mark Banner
+// - - -
-// - - - - - - - - - - - - - - - - - - - - - - - - - -
++ (CGSize) bannerSizeForOrientation: (UIInterfaceOrientation) ori
+{
+ NSString * token = [self bannerTokenForOrientation: ori];
+
+ CGSize bannerSize = [ADBannerView sizeFromBannerContentSizeIdentifier: token];
+
+ return bannerSize;
+}
+
+// = = = = = = = = = = = = = = = = = = = = = = = = = =
+#pragma mark things that change layout
- (void) bannerViewDidLoadAd: (ADBannerView *) banner
-{
- if (! showingBanner)
+{
+ CGSize bannerSize = [iAdVC bannerSizeForOrientation: self.interfaceOrientation];
+ CGRect bannerRect = CGRectMake(0, 0, bannerSize.width, bannerSize.height);
+
+ // exchange old ad for new
+ if ( ! self.adBannerView.hidden )
{
- showingBanner = YES;
- // ... (optionally animate in)
+ // whoosh off to side
+ [UIView animateWithDuration: 0.33
+ delay: .0
+ options: (UIViewAnimationOptions) 0
+ animations: ^ { self.adBannerView.frame = CGRectOffset(bannerRect, -bannerSize.width, 0); }
+ completion: ^ (BOOL ret) {
+ // ... & whoosh new one in
+ [UIView setAnimationsEnabled:NO];
+ self.adBannerView.frame = CGRectOffset(bannerRect, bannerSize.width, 0);
+ [UIView setAnimationsEnabled:YES];
+
+ [UIView animateWithDuration: .33
+ delay: .0
+ options: (UIViewAnimationOptions) 0
+ animations: ^ { self.adBannerView.frame = bannerRect; }
+ completion: nil
+ ];
+ }
+ ];
+
+ return;
}
-}
+
+ else
+ {
+ // start banner offscreen
+ [UIView setAnimationsEnabled:NO];
+ {
+ self.adBannerView.frame = CGRectOffset(bannerRect, 0, -bannerSize.height);
+ }
+ [UIView setAnimationsEnabled:YES];
+
+ // ... & drop ad in from top, squashing content-view
+ self.adBannerView.hidden = NO;
+
+ CGRect newContentFrame = uberView.bounds;
+ newContentFrame.size.height -= bannerSize.height;
+ newContentFrame.origin.y += bannerSize.height;
+
+ [UIView animateWithDuration: .9
+ delay: .0
+ options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionLayoutSubviews
+ animations: ^ {
+ self.contentView.frame = newContentFrame;
+ self.adBannerView.frame = bannerRect;
+ }
+ completion: nil
+ ];
+
+ return;
+ }
+}
// - - - - - - - - - - - - - - - - - - - - - - - - - -
- (void) bannerView: (ADBannerView *) banner
didFailToReceiveAdWithError: (NSError *) error
{
- NSLog(@"FAIL");
-
- if (showingBanner)
+ if (! self.adBannerView.hidden)
{
- showingBanner = NO;
- // ... (optionally animate out)
+ CGSize bannerSize = [iAdVC bannerSizeForOrientation: self.interfaceOrientation];
+ CGRect bannerRect = CGRectMake(0, 0, bannerSize.width, bannerSize.height);
+
+ // slide banner up & out ...
+ [UIView animateWithDuration: .9
+ delay: .0
+ options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionLayoutSubviews
+ animations: ^ {
+ self.contentView.frame = uberView.bounds;
+ self.adBannerView.frame = CGRectOffset(bannerRect, 0, -bannerSize.height);
+ }
+ completion: ^ (BOOL ret) { self.adBannerView.hidden = YES; }
+ ];
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - -
--(BOOL) bannerViewActionShouldBegin: (ADBannerView *) banner
- willLeaveApplication: (BOOL) willLeave
+- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) newOrientation
+ duration: (NSTimeInterval) duration
{
- return YES;
+ bool isLandscape = UIInterfaceOrientationIsLandscape(newOrientation);
+ self.adBannerView.currentContentSizeIdentifier = isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait ;
+
+ if (! adBannerView.hidden)
+ {
+ CGSize bannerSize = [iAdVC bannerSizeForOrientation: newOrientation];
+ CGRect bannerRect = CGRectMake(0, 0, bannerSize.width, bannerSize.height);
+
+ CGRect newContentFrame = uberView.bounds;
+ newContentFrame.size.height -= bannerSize.height;
+ newContentFrame.origin.y += bannerSize.height;
+
+ [UIView animateWithDuration: duration
+ delay: .0
+ options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionLayoutSubviews
+ animations: ^ {
+ self.contentView.frame = newContentFrame;
+ self.adBannerView.frame = bannerRect;
+ }
+ completion: nil
+ ];
+ }
}
// = = = = = = = = = = = = = = = = = = = = = = = = = =
-
#pragma mark Tidy-up
-- (void)didReceiveMemoryWarning {
+
+- (void) didReceiveMemoryWarning
+{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
@@ -129,14 +257,16 @@ - (void)didReceiveMemoryWarning {
- (void) viewDidUnload
-{
-}
+{ }
- (void) dealloc
{
- [self.adBannerView removeFromSuperview]; self.adBannerView.delegate = nil; [self.adBannerView release]; self.adBannerView = nil;
+ [self.adBannerView removeFromSuperview];
+ self.adBannerView.delegate = nil;
+ self.adBannerView = nil;
- [self.uberView removeFromSuperview]; [self.uberView release]; self.uberView = nil;
+ [self.uberView removeFromSuperview];
+ self.uberView = nil;
[super dealloc];
}
View
6,709 ...deproj/project.xcworkspace/xcuserdata/sunfish7.xcuserdatad/UserInterfaceState.xcuserstate
3,394 additions, 3,315 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
12 ...ROJECTNAME___.xcodeproj/xcuserdata/sunfish7.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -9,11 +9,11 @@
continueAfterRunningActions = "No"
isPathRelative = "1"
filePath = "Classes/iAdVC.m"
- timestampString = "323097101.082636"
+ timestampString = "323526439.765665"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "35"
- endingLineNumber = "35"
+ startingLineNumber = "46"
+ endingLineNumber = "46"
landmarkName = "-makeViewUsingFrame:"
landmarkType = "5">
</FileBreakpoint>
@@ -23,11 +23,11 @@
continueAfterRunningActions = "Yes"
isPathRelative = "1"
filePath = "Classes/AppDelegate.m"
- timestampString = "323094139.593642"
+ timestampString = "323111579.32888"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "33"
- endingLineNumber = "33"
+ startingLineNumber = "31"
+ endingLineNumber = "31"
landmarkName = "-application:didFinishLaunchingWithOptions:"
landmarkType = "5">
<Actions>

0 comments on commit 2f9cd80

Please sign in to comment.