背景: 上周我问了一个关于在多个viewControllers中使用adWhirl的问题,但不幸的是我仍然没有得到它。如何避免使每个viewController成为adWhirl委托? (有没有AdWhirl设计模式)
我接受了这些建议,现在在每个viewController中使用一个在应用程序委托中创建的adWhirl实例,但我没有看到自我的viewController(等)中如何响应adWhirl委托事件委托人不知道哪个viewController当前正在显示其adView。
因此我的困惑...
有没有这样的设计模式?我会认为必须有。如果我能避免它,我不想用模板adWhirl委托代码来编写我的所有viewController。
我现在在每个viewController中都有下面的内容。我试图在应用程序委托中设置一个方法,每个视图控制器可以调用“注册”来取得应用程序委托人的adView的所有权 - 认为当委托人收到类似adWhirlDidReceiveAd
的事件时,它可以执行下面的工作。这种工作方式,但让我认为我正在重新发明轮子。
问题:是否有跨多个viewControllers使用adWhirl视图的设计模式?
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[self.view addSubview:appDelegate.adView];
[self.view bringSubviewToFront:appDelegate.adView];
CGSize adSize = [appDelegate.adView actualAdSize];
CGRect onScreenFrame = appDelegate.adView.frame;
onScreenFrame.size.height = adSize.height; // fit the ad
onScreenFrame.size.width = adSize.width;
onScreenFrame.origin.x = (self.view.frame.size.width - adSize.width)/2; // center
onScreenFrame.origin.y = (self.view.frame.size.height - adSize.height);
appDelegate.adView.frame = onScreenFrame;
}
- (void)viewDidDisappear:(BOOL)animated
{
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.adView removeFromSuperview];
}
谢谢 - 得到它的工作。对初学者不是很明显...... –