我安装AdMob的广告,并有一个GADBannerView上。如何只允许特定视图旋转? (iPhone)
安装完成后,旗帜展示,如果你点击它,页面会滑出拱整个屏幕,并在其中显示广告内容。
的问题是,一些广告内容,如视频,必须发挥景观。不过,我不希望我的应用程序的其他部分旋转,因为应用程序没有设计在景观中查看。
那么,我该如何实现一些可以实现这种功能的东西呢?
我安装AdMob的广告,并有一个GADBannerView上。如何只允许特定视图旋转? (iPhone)
安装完成后,旗帜展示,如果你点击它,页面会滑出拱整个屏幕,并在其中显示广告内容。
的问题是,一些广告内容,如视频,必须发挥景观。不过,我不希望我的应用程序的其他部分旋转,因为应用程序没有设计在景观中查看。
那么,我该如何实现一些可以实现这种功能的东西呢?
你看过这个问题和答案吗?这就解释了如何在单个视图可以在一定的方向不是由应用程序的其余部分支持工作:
尝试使用通知这一点。每当设备方向改变时,通知会调用选择器。
写这在您的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");
}
}
此法进行烧结,每次当乌尔设备改变方向。根据当前的方向,您应该调整视图。
我希望这会帮助你。
你在使用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;
}
,并应让这个您的视图控制器仅支持肖像。