Brade
Brade

Reputation: 1531

iOS - entire View shifts up after rotation

Doing a very simple iPad app that plays a video in fullscreen. I want the video perfectly centered, but on initial load it's a bit too far down. When I rotate it, the view resets itself properly to be perfectly centered. Obviously I'd love to have it look this way from the start.

Here's my code in viewDidLoad:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"movie" ofType:@"m4v"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer prepareToPlay];
CGRect screenBounds = [UIScreen mainScreen].bounds;
[moviePlayer.view setFrame:CGRectMake(0, 0, screenBounds.size.height, screenBounds.size.width)];
[self.view addSubview:moviePlayer.view];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayer play];
[super viewDidLoad];

The app is set to only show in landscape mode, so the rotation takes effect every 180 degrees (instead of 90). BTW the moviePlayer var is set in the .h file like so:

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;

Then it's synthesized in my ViewController:

@synthesize moviePlayer;

So does anyone have any ideas? I tried changing "setFrame" to start at 0,-20 instead of 0,0 but that messed things up on the later rotations. If there's a way to ignore the dumb status bar on initial load, I'd love to know it. Thanks.

Upvotes: 2

Views: 278

Answers (2)

user1459524
user1459524

Reputation: 3603

Try calling

[self setWantsFullScreenLayout:YES];

in the viewcontroller implementation. This should force it to "ignore the dumb status bar on initial load".

Upvotes: 2

Chris C
Chris C

Reputation: 3251

Try setting the frame in -viewDidLayoutSubviews. Layout should be handled there, not in the setup methods.

Upvotes: 4

Related Questions