我安裝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;
}
,並應讓這個您的視圖控制器僅支持肖像。