我已經連續三天嘗試將廣告整合到我的iPhone遊戲中。我選擇了mobfox,除了一些與我的Objective-C技能水平低的直接相關的細節外,它一直進展順利。調用bringSubviewToFront會給出錯誤
我有一切工作,除了廣告被UI元素遮擋。所以,我希望把廣告的正面和周圍一派,設法弄清楚這一點:
[self.view bringSubviewToFront:bannerView];
然而,因爲代碼是(無效)viewDidLoad中只能使用一次。然後我嘗試在我的代碼的其他地方,在UI初始化等使用相同的代碼,但我然後得到一個錯誤,沒有聲明bannerView。我非常瞭解xcode告訴我的是什麼,但我不具備簡單地聲明和完成的技能,我不知道如何才能問我能否幫助我?
我想要做的就是從代碼中的任意位置隨意將我的bannerView放在前面。 你能幫我嗎?
此致 馬庫斯
下面是的MobFox代碼
以下是在viewDidLoad中
// MOBFOX Starts
// create the banner view just outside of the visible area
MobFoxBannerView *bannerView = [[MobFoxBannerView alloc] initWithFrame:
CGRectMake(-800, self.view.bounds.size.height - 240, 320, 50)];
bannerView.delegate = self; // triggers ad loading
//bannerView.backgroundColor = [UIColor darkGrayColor]; // fill horizontally
bannerView.transform = CGAffineTransformMakeRotation(M_PI/2.0); //MARCUS haxx
//bannerView.refreshAnimation = UIViewAnimationTransitionCurlDown;
[self.view addSubview:bannerView];
[self.view bringSubviewToFront:bannerView];
NSLog(@"MobFox: Ad initated and placed offscreen");
//
這直接是viewDidLoad中後的我想去
//MOBFOX STARTS HERE
#pragma mark MobFox Delegate
- (NSString *)publisherIdForMobFoxBannerView:(MobFoxBannerView *)banner
{
return kMyMobFoxPublisherId;
}
- (void)mobfoxBannerViewDidLoadMobFoxAd:(MobFoxBannerView *)banner
{
NSLog(@"MobFox: did load ad and placed on screen");
// animate banner into view
//[UIView beginAnimations:@"MobFox" context:nil];
//[UIView setAnimationDuration:1];
banner.frame = CGRectMake(135, 140, 320, 50);
[UIView commitAnimations];
}
- (void)mobfoxBannerView:(MobFoxBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"MobFox: did fail to load ad: %@", [error localizedDescription]);
// animate banner outside view
//[UIView beginAnimations:@"MobFox" context:nil];
//[UIView setAnimationDuration:1];
banner.frame = CGRectMake(-800, self.view.bounds.size.height - 240, 320, 50);
[UIView commitAnimations];
}
//MOBFOX ENDS HERE
實施例喜歡調用bringSubViewToFront:bann erView但不能
-(void) settitleMenuToFront {
[self.view bringSubviewToFront:titleScreenImg];
[self.view bringSubviewToFront:highScoreTable];
[self.view bringSubviewToFront:ContinueButton];
[self.view bringSubviewToFront:highscoreButton];
[self.view bringSubviewToFront:newgameButton];
if (loadingScreen.alpha > 1) {
[self.view bringSubviewToFront:loadingScreen];
}
}
不知道它是否必須是私人的,但你不只是發佈你的真實廣告發布者ID,對嗎? :) – Vladimir