我可能是我,但我一直在努力爭取2天的時間來讓iAd框架與我正在開發的一個項目中的cocos2d一起工作。無法讓iAd橫幅與cocos2d一起工作
我有搜索谷歌,stackoverflow和cocos2d論壇,但沒有運氣。 我已經下載並嘗試了很多來自stackoverflow站點和其他資源的示例。 當我把我的當前項目的代碼結合起來,它不會工作。 不滿意的結果差異很大,它可能會混淆他人,這就是爲什麼我還沒有發佈代碼與此請求。無論如何,代碼也可以在stackoverflow網站上找到,並且我已經加入了一些我已經嘗試過的鏈接。 有一刻我非常接近解決方案,但是特定的遷移使AppDelegate方法搞砸了。 AppDelegate方法有2 @interface部分。我試圖解決這個問題,但無法弄清楚如何解決它,並重新開始面對以前的備份問題。
誰可以幫助我在一些示例代碼中將我推向正確的方向。
這裏下面的一些東西/鏈接,我都準備好了嘗試:
http://www.highoncoding.com/Articles/751_Implementing_iAd_on_Cocos2d_Application.aspx (太老)
iAd ADBannerView detect unloading
https://www.youtube.com/watch?v=fP2ijcXbCz4
在此先感謝
下面的代碼是一個讓我某種藍色旗幟的底部側關閉屏幕最接近。這不是我自己的,評論不是我的。
-(id) init
{
if((self=[super init])) {
UIViewController *controller = [[UIViewController alloc] init];
controller.view.frame = CGRectMake(0, size.height -32, 320, 32);
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierLandscape];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
[controller.view addSubview:adView];
adView.delegate = self;
[[[CCDirector sharedDirector] view] addSubview:controller.view];
[[[CCDirector sharedDirector] view] setNeedsLayout];
}
[self layoutAnimated:YES];
}
- (void)layoutAnimated:(BOOL)animated
{
// As of iOS 6.0, the banner will automatically resize itself based on its width.
// To support iOS 5.0 however, we continue to set the currentContentSizeIdentifier appropriately.
CGRect contentFrame = [CCDirector sharedDirector].view.bounds;
if (contentFrame.size.width < contentFrame.size.height) {
//_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[adView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}
[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
_bannerView.frame = bannerFrame;
}];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!bannerIsVisible)
{
NSLog(@"bannerViewDidLoadAd");
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -32); //the offending line
self.position = ccpAdd(ccp(0, 32), self.position);
[UIView commitAnimations];
bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (bannerIsVisible)
{
NSLog(@"bannerView:didFailToReceiveAdWithError:");
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 32); //the other offending line
self.position = ccpAdd(ccp(0, -32), self.position);
[UIView commitAnimations];
bannerIsVisible = NO;
}
}
喬治,我明白了! 我在這裏找到了解決方案, https://github.com/gururajios/Cocos2d-iAd 謝謝 –