0
votes

I'm working on this cocos2D app that only supports landscape orientation. There is this UIView that is being displayed perpendicular, as if the device was in portrait orientation. I have two questions:

  • Why is why is it being displayed perpendicular?
  • Is it possible to get it to display properly without manually rotating the view?

Here is the code in the view controller:

// 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);
}

Update

I found out that if it add it to the openGLView then it is fine.

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

instead of

[self.view addSubview: _blockerView];

works

I suspect the view its currently in got rotated somehow.

2
Screenshot? Is _blockerView the view you're talking about? Quick comment - you don't need to set the center of _blockerView if you've already initialized it using a certain frame. - sparkFinder
Yes, _blockerView is the one that is rotated. I didn't write this code. I just work here, lol. Thanks for the tip though. - Jay

2 Answers

1
votes

Please check the view controller for a method called shouldAutorotateToInterfaceOrientation:. Yours should answer like this:

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

Is their a tab bar controller present? If so, that's a potential gotcha: all the view controllers of the tab bar need to agree on orientation.

0
votes

Did you turn on in your project property list portrait orientation ?

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