0

我已经浏览了bees4honey、iadsuites 样本(全部三个),以及大家最喜欢的raywenderlich 导师。他们都没有帮助我展示横幅。我没有大多数导师通常提到的任何xib。这是我的委托代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after app launch
    // Create the window object
    UIWindow *localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Assign the localWindow to the AppDelegate window, then release the local window
    self.window = localWindow;
    [localWindow release];

    // Setup the first view controller
    HomeViewController *homeViewController = [[HomeViewController alloc] init];

    // Initialise the navigation controller with the first view controller as its root view controller
    navigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];

        [navigationController.navigationBar setBarStyle:UIBarStyleBlack];

    [navigationController.navigationBar setTintColor:[UIColor blackColor]];
            //[navigationController setNavigationBarHidden:YES];


        [HomeViewController release];



    // Add the navigation controller as a subview of our window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];

    return YES;
}

我有 HomeViewController(用于导航和方法)和 HomeView(用于子视图)。我的 homeviewcontroller.m 示例

#pragma mark -
#pragma mark Initialisation

- (id)init {
    self = [super init];
    if (self) {
        self.title = @"Home";

        UIView *homeView = [[HomeView alloc] initWithParentViewController:self];
        self.view = homeView;

        [homeView release];
    }
    return self;
}

#pragma mark -
#pragma mark Action Methods

- (void)button3Action {...........rest of code below as method for the button located in HomeView.m

来自 Homeview.m 的示例代码

// Private Methods
@interface HomeView()
- (void)loadButton3;

@end

@implementation HomeView

#pragma mark -
#pragma mark Initialization

- (id)initWithParentViewController:(HomeViewController *)parent {
    if ((self = [super init])) {
        // Update this to initialize the view with your own frame size
        // The design has specified that there is to be no status bar present,
        // please hide the status bar.
        [self setFrame:CGRectMake(0, 0, 320, 480)];

        // Assign the reference back to the parent view controller
        refParentViewController = parent;

        // Set the view background color
        [self setBackgroundColor:[UIColor lightGrayColor]];

        // Load subview methods
        [self loadButton3];

    }
    return self;
}

#pragma mark -
#pragma mark Load Subview Methods

- (void)loadButton3 {
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button3 setTitle:@"Is that counterfeit product?" forState:UIControlStateNormal];
    [button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button3 setBackgroundColor:[UIColor clearColor]];
                button3.titleLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:25];
    [button3 addTarget:refParentViewController action:@selector(button3Action) forControlEvents:UIControlEventTouchUpInside];
    [button3 setFrame:CGRectMake(5, 375, 310, 31)];
    [self addSubview:button3];
}

如果有人可以帮助我找出我需要将“苹果批准的代码”放在我的项目中以显示横幅的确切位置,那就太好了。

谢谢 =)

4

1 回答 1

1

根据我对 ADBannerNavigation 中 Apple 代码的回答,您可以将其简化为检查广告出现的必要条件。我是说 :

1) 获取应用程序委托中的代码,定义 iAd 和 SharedADBannerView,并在 appdelegate.m 中:

adBanner = [[ADBannerView alloc] initWithFrame:CGRectZero];

// Set the autoresizing mask so that the banner is pinned to the bottom
self.adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;

// Since we support all orientations, support portrait and landscape content sizes.
// If you only supported landscape or portrait, you could remove the other from this set
self.adBanner.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

2)因此,当您的控制器进入视图时,实例就存在,您可以添加 viewDidAppear Apple 的代码,但将原点更改为可见的内容(Apple 建议将其置于视图之外,然后将其动画化,这很好,但在第一步检查它在这里):

    ADBannerView *adBanner = SharedAdBannerView;

// Depending on our orientation when this method is called, we set our initial content size.
// If you only support portrait or landscape orientations, then you can remove this check and
// select either ADBannerContentSizeIdentifierPortrait (if portrait only) or ADBannerContentSizeIdentifierLandscape (if landscape only).
NSString *contentSize;
contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierLandscape;


// Calculate the intial location for the banner.
// We want this banner to be at the bottom of the view controller, but placed
// offscreen to ensure that the user won't see the banner until its ready.
// We'll be informed when we have an ad to show because -bannerViewDidLoadAd: will be called.
CGRect frame;
frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSize];
frame.origin = CGPointMake(0.0f, 100)); // CHANGE TO APPLE'S CODE

// Now set the banner view's frame
adBanner.frame = frame;

// Set the delegate to self, so that we are notified of ad responses.
adBanner.delegate = self;

// Set the autoresizing mask so that the banner is pinned to the bottom
adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;

// Since we support all orientations in this view controller, support portrait and landscape content sizes.
// If you only supported landscape or portrait, you could remove the other from this set
adBanner.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

// At this point the ad banner is now be visible and looking for an ad.
[self.view addSubview:adBanner];

此时,您已经在视图中添加了横幅,因此即使未实现委托方法,它也应该出现。完成这项工作后,您可以详细说明管理动画的委托方法。

于 2011-10-20T12:50:21.717 回答