Reputation: 9582
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:
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.
Upvotes: 0
Views: 592
Reputation: 5099
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>
Upvotes: 0
Reputation: 62686
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.
Upvotes: 1