问题
I've the requirement to show video as splash screen in my iphone app I'm using following code:
-(void)setupMovie{
NSString* moviePath = [[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"mp4"];
NSURL* movieURL = [NSURL fileURLWithPath:moviePath];
playerCtrl = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
playerCtrl.scalingMode = MPMovieScalingModeFill;
playerCtrl.controlStyle = MPMovieControlStyleNone;
playerCtrl.view.frame = CGRectMake(0, 0, 480, 320);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[playerCtrl.view setCenter:CGPointMake(240, 160)];
[playerCtrl.view setFrame:CGRectMake(0, 0, 480, 320)];
[playerCtrl.view setTransform:CGAffineTransformMakeRotation(-M_PI/2)];
[self.window addSubview:playerCtrl.view];
[playerCtrl play];}
But the player view is not starting at x=0,y=0 location. What's the reason and how to fix it. Its starting x=100,y=100 (approx).
回答1:
you are setting the information which affects the position three times
playerCtrl.view.frame = CGRectMake(0, 0, 480, 320);
[playerCtrl.view setCenter:CGPointMake(240, 160)];
[playerCtrl.view setFrame:CGRectMake(0, 0, 480, 320)];
so try one after another
回答2:
Set frame after rotation:
playerCtrl.view.frame = CGRectMake(0, 0, 320, 480);
来源:https://stackoverflow.com/questions/4575273/iphone-showing-video-as-a-splash-screen