ムービープレーヤービューを明示的に回転させたい(オートローテーションデリゲートを使用しない)。私はそれのために次のコードを書いて、その中にコメントを入れました。ムービープレーヤの親ビューは回転しますが、ムービープレーヤビュー自体は回転しません。誰かがここで私が間違ってやっていることを助けてくれますか?ありがとう。iOS:ムービープレーヤービューが回転しない
#import "CustomMoviePlayer.h"
#define degreesToRadian(x) (M_PI * (x)/180.0)
#define radianToDegrees(x) ((x) * 180.0/M_PI)
@implementation CustomMoviePlayer
@synthesize moviePlayer, myParentViewController;
-(void)playMovie:(NSString*)filePath onViewController:(UIViewController*)controller
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotateMoviePlayer) name: UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
myParentViewController = controller;
NSURL *url = [NSURL fileURLWithPath:filePath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:moviePlayer];
[controller.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void)moviePlaybackStateChanged:(NSNotification *)notification
{
NSLog(@"State changed... %d", [moviePlayer playbackState]);
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
NSLog(@"Finished video...");
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
[myParentViewController.view setTransform:CGAffineTransformIdentity];
[moviePlayer.view removeFromSuperview];
[moviePlayer release];
}
-(void)rotateMoviePlayer
{
NSLog(@"Rotate movie player");
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation != UIDeviceOrientationUnknown) {
CGAffineTransform transform = CGAffineTransformMakeRotation(degreesToRadian(0));
switch (orientation) {
case UIDeviceOrientationLandscapeLeft:
transform = CGAffineTransformMakeRotation(M_PI/2);
break;
case UIDeviceOrientationLandscapeRight:
transform = CGAffineTransformMakeRotation(-M_PI/2);
break;
case UIDeviceOrientationPortraitUpsideDown:
transform = CGAffineTransformMakeRotation(M_PI);
break;
default:
break;
}
// This view does rotate and I can see it rotating when there is no moviePlayer on top of it!
[myParentViewController.view setTransform:CGAffineTransformIdentity];
[myParentViewController.view setTransform:transform];
// It doesn't mater whether I put following two lines or not...Movie player view doesn't rotate!
[moviePlayer.view setTransform:CGAffineTransformIdentity];
[moviePlayer.view setTransform:transform];
}
}
- (void)dealloc {
[moviePlayer release];
[super dealloc];
}
@end
あなたのコードはほとんど読めるものではありません。一般的な方法に従って、コードを再フォーマットしてください。また、(インスタンス)変数に初期大文字を使用しないようにしてください。 – Till
ありがとう@till。書式設定を完了しました! – applefreak