Objective c UIView的方向不正确

Objective c UIView的方向不正确,objective-c,ios,cocoa-touch,uiview,cocos2d-iphone,Objective C,Ios,Cocoa Touch,Uiview,Cocos2d Iphone,我正在开发这个只支持横向定位的cocos2D应用程序。有一个垂直显示的UIView,就好像设备是纵向的。我有两个问题: 为什么要垂直显示 是否可以在不手动旋转视图的情况下使其正确显示 以下是视图控制器中的代码: // this method is called from init -(void) addLoadingView { CGSize size = [[CCDirector sharedDirector] winSize]; _blockerView

我正在开发这个只支持横向定位的cocos2D应用程序。有一个垂直显示的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];
而不是

[self.view addSubview: _blockerView];
工作


我怀疑其当前所在的视图以某种方式发生了旋转。

请检查视图控制器中是否有名为shouldAutorotateToInterfaceOrientation:的方法。你的回答应该是这样的:

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

他们的选项卡栏控制器是否存在?如果是这样的话,这可能是一个问题:选项卡栏的所有视图控制器都需要在方向上达成一致。

是否在项目属性列表中启用了纵向方向

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
</array>
UI支持接口方向
UIInterfaceOrientationPortrait
UIInterfaceOrientationAndscapeRight
UIInterface方向和左视图

屏幕截图?你说的是blockerView吗?快速评论-如果已经使用某个帧初始化了_blockerView,则不需要设置它的中心。是的,_blockerView是旋转的。这不是我写的代码。我只是在这里工作,哈哈。不过谢谢你的提示。不是这样的。自动旋转很好,只是通过旋转来绘制。我怀疑是superview旋转了什么的。