2012-03-23 76 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>