2011-11-11 70 views
24

因此,正如標題所說,我在iPad上有一個hdmi和註冊用於屏幕連接的觀察者,一旦連接,用戶選擇res並輸出一個視圖。但是,如果我從筆尖或甚至從程序視圖控制器加載視圖,則ipad將以縱向顯示橫向視圖(是的,兩種情況均設置爲橫向)。IOS - 外部(HDMI)輸出只填充屏幕的一半,除非手動編碼視圖

I.e.

ExternalViewController *ex = [[ExternalViewController alloc] init]; 
[externalWindow setRootViewController:ex]; 

做到這一點:

Bad 如果我創建視圖本身編程。像這樣:

UIView *test = [[UIView alloc] initWithFrame:[externalScreen applicationFrame]]; 
[test setBackgroundColor:[UIColor whiteColor]]; 
UILabel *msgLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, 100, 30)]; 
msgLabel.text = @"External!"; 
[test addSubview:msgLabel]; 

它運行像某種形式的神奇夢想:

good

但是我希望視圖 - 控制加載(而努力!)所以,StackOverflow的,我問你。有沒有人遇到過這個?

編輯:它不用說,常見的感性答案不會得到賞金,我是在修復後,而不是解決方法。有了我有限的大腦,我所能想到的就是創建一個方法,根據它的輸入創建一個視圖,並將其作爲外部監視器的子視圖,很明顯這是一種黑客解決方案,因此我們希望能夠解決這個問題!謝謝!

編輯:

-(id)initWithFrame:(CGRect)_rect 
{ 
    rect = _rect; 
    if (self = [super init]) 
    { 
     externalView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"105.png"]]; 
     externalView.alpha = 0.0; 
     [externalView setFrame:rect]; 
     [externalView setBackgroundColor:[UIColor yellowColor]]; 
     self.view = [[UIView alloc] initWithFrame:rect]; 
     self.view.backgroundColor = [UIColor whiteColor]; 

     return self; 
    } 
} 

- (void)loadView 
{ 
    self.view = [[UIView alloc] initWithFrame:rect]; 
    self.view.backgroundColor = [UIColor blackColor]; 
    [self.view addSubview:externalView]; 
} 

按照要求,這是我如何加載視圖 - 控制與外部屏幕的大小初始化。謝謝

+0

「縱向景觀視圖」被截斷或旋轉了嗎?我的意思是,如果您在第二個示例中添加了標籤,它會顯示在屏幕左上角還是左下角呈90度? – jrturton

+0

對不起,應該說明一下。當您在屏幕的一半中看到視圖時,它是風景但旋轉。所以,如果我添加一個標籤,那麼它會顯示它隨着從下到上的文本旋轉。 –

+0

你可以包含來自'nibless'視圖控制器的'loadView'方法的代碼,展示如何創建視圖,從哪裏獲取外部顯示的尺寸等? – jrturton

回答

4

只需在您的UIViewController子類中返回- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation中的NO即可。

// ugly, don't use this in real code 

if ([UIScreen screens].count == 1) return; // just one screen, eww. 

// getting the secondary screen 
UIScreen *screen = [[UIScreen screens] objectAtIndex:1]; 

__block UIScreenMode *highestWidthMode = NULL; 

[screen.availableModes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
    UIScreenMode *currentModeInLoop = obj; 
    if (!highestWidthMode || currentModeInLoop.size.width > highestWidthMode.size.width) 
    highestWidthMode = currentModeInLoop; 
}]; 

// setting to the highest resolution available 
screen.currentMode = highestWidthMode; 

NSLog(@"screen.currentMode = %@", screen.currentMode); 
screen.overscanCompensation = UIScreenOverscanCompensationScale; 


// initializing screen 
secondWindow = [[UIWindow alloc] initWithFrame:[screen bounds]]; 
[secondWindow setScreen:screen]; 

// other view is a UIViewController, just remember to return NO in - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation or the iOS will rotate the frame. 

UIViewController *vc = [[OtherView alloc] initWithNibName:@"OtherView" bundle:nil]; 
secondWindow.rootViewController = vc; 
[secondWindow makeKeyAndVisible]; 
+0

不用,試過了。我相信這個觀點確實相信它在景觀上輸出到必要的畫面。 –

+0

我會上傳一個工作示例,一秒鐘。 –