2012-03-23 80 views
0

我正在研究只支持橫向的cocos2D應用程序。有這個垂直顯示的UIView,就好像該設備是縱向的。我有兩個問題:UIView有錯誤的方向

  • 爲什麼爲什麼它顯示爲垂直?
  • 是否可以在不手動旋轉視圖的情況下正確顯示它?

這裏是在視圖控制器代碼:

// this method is called from init 
-(void) addLoadingView {  
     CGSize size = [[CCDirector sharedDirector] winSize]; 

    _blockerView = [[[UIView alloc] 
     initWithFrame: CGRectMake(0, 0, 280, 60)] autorelease]; 
    _blockerView.backgroundColor = [UIColor colorWithWhite: 0.0 alpha: 0.8]; 
    _blockerView.center = CGPointMake(size.width/2, size.height/2); 
    _blockerView.alpha = 0.0; 
    _blockerView.clipsToBounds = YES; 
    if ([_blockerView.layer respondsToSelector: @selector(setCornerRadius:)]) 
     [(id) _blockerView.layer setCornerRadius: 10]; 

    _blockerLabel = [[[UILabel alloc] initWithFrame: CGRectMake(0, 5, _blockerView.bounds.size.width, 15)] autorelease]; 
    _blockerLabel.text = NSLocalizedString(@"Please Wait...", nil); 
    _blockerLabel.backgroundColor = [UIColor clearColor]; 
    _blockerLabel.textColor = [UIColor whiteColor]; 
    _blockerLabel.textAlignment = UITextAlignmentCenter; 
    _blockerLabel.font = [UIFont boldSystemFontOfSize: 15]; 
    [_blockerView addSubview: _blockerLabel]; 

    UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] 
     initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhite] autorelease]; 

    spinner.center = CGPointMake(_blockerView.bounds.size.width/2, _blockerView.bounds.size.height/2 + 10); 
    [_blockerView addSubview: spinner]; 
    [self.view addSubview: _blockerView]; 
    [spinner startAnimating]; 
} 

-(void) showLoadingGraphics:(NSString*)textInView{ 
    _blockerView.alpha = 1.0; 
    _blockerLabel.text = NSLocalizedString(textInView, nil); 
} 

更新

我發現,如果把它添加到openGLView那麼它是好的。

[[[CCDirector sharedDirector] openGLView] addSubview: _blockerView]; 

代替

工作

我懷疑它目前在某種程度上得到了旋轉的視圖。

+0

截圖? _blockerView是你正在談論的視圖嗎? 快速評論 - 如果您已經使用特定框架對其進行了初始化,則無需設置_blockerView的中心。 – sparkFinder 2012-03-23 20:00:53

+0

是的,_blockerView是一個旋轉。我沒有寫這個代碼。我只是在這裏工作,哈哈。謝謝你的提示。 – Jay 2012-03-23 20:09:46

回答

1

請檢查視圖控制器的方法稱爲shouldAutorotateToInterfaceOrientation :.你應該這樣回答:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
      interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

他們是否存在標籤欄控制器?如果是這樣,這是一個潛在的問題:標籤欄的所有視圖控制器需要就方向達成一致。

+0

那不是。自動旋轉很好,只是旋轉畫出來的。我懷疑一些superview被旋轉了或者什麼。 – Jay 2012-03-23 21:09:55

0

你打開你的項目屬性列表縱向?

<key>UISupportedInterfaceOrientations</key> 
<array> 
    <string>UIInterfaceOrientationPortrait</string> 
    <string>UIInterfaceOrientationLandscapeRight</string> 
    <string>UIInterfaceOrientationLandscapeLeft</string> 
</array>