我正在安装AdMob的广告,并且有一个GADBannerView。
安装完毕后,横幅展示,如果点击它,页面将滑出整个屏幕,并在其中显示广告内容。
问题是,一些广告内容,如视频,必须播放风景。但是,我不希望我的应用程序的其他部分旋转,因为该应用程序不是为横向浏览而设计的。
那么,我怎样才能实现能够实现这种功能的东西呢?
答案 0 :(得分:1)
尝试使用通知。每次更改设备方向时,通知都会调用选择器。
在viewDidLoad中写下这个:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setScreenWithDeviceOrientation:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
然后按如下方式定义选择器:
-(void)setScreenWithDeviceOrientation:(NSNotification *)notification
{
UIDeviceOrientation orientation=[[UIDevice currentDevice] orientation];
if(orientation==UIInterfaceOrientationPortrait) //Portrait orientation
{
// setView frame for portrait mode
}
else if(orientation==UIInterfaceOrientationPortraitUpsideDown) // PortraitUpsideDown
{
// setView frame for upside down portrait mode
}
else if(orientation==UIInterfaceOrientationLandscapeLeft)
{
// setView frame for Landscape Left mode
}
else if(orientation==UIInterfaceOrientationLandscapeRight) //landscape Right
{
// setView frame for Landscape Right mode
}
else
{
NSLog(@"No Orientation");
}
}
每次当你的设备改变方向时,都会触发此方法。根据当前的方向,您应该调整视图。
我希望这会对你有所帮助。
答案 1 :(得分:1)
你在使用iOS 6吗?在这种情况下,您应该能够限制视图控制器处理的方向。例如,在处理GADBannerView的视图控制器中,您可以放置:
// Tell the system what we support
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return NO;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
这应该使你的viewcontroller只支持肖像。
答案 2 :(得分:0)