2

私のアプリを使用しているとき、ユーザーはリストに表示されているビデオをクリックして見ることができます。そのビデオをクリックすると、向きを縦向きまたは横向きに変更できます。リストページはポートレートのみです。

私が直面しているエラーは、ユーザーが横向きでビデオを視聴し、横向きでページを終了すると、リストページがすべて台無しになることです。

ユーザーがビデオで[完了]を押してリストに戻るたびに、向きを縦向きに戻す方法が必要です。

リストページに私は持っています

- (BOOL)shouldAutorotate{
  return YES;
}

そしてshouldAutorotate、viewDidAppearでメソッドを呼び出そうとしましたが、それは機能しません。ページが読み込まれた後に呼び出されないことはわかっているshouldAutorotateので、向きを確認して裏返すか、何があっても縦向きにする方法はありますか?

まだランドスケープが必要なので、plistファイルから削除しません。

どんな助けでも素晴らしいでしょう。ありがとう

編集

これが私のビデオプレーヤーの呼び方です

    MPMoviePlayerViewController *player=[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[[main_data objectAtIndex:indexPath.row] objectForKey:@"url"]]];

    UIView * playerView = [player view];
    [playerView setFrame: CGRectMake(0, 0, 480, 320)];

    CGAffineTransform landscapeTransform;
    landscapeTransform = CGAffineTransformMakeRotation(90*M_PI/180.0f);
    landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);

    [playerView setTransform: landscapeTransform];

    [self presentMoviePlayerViewControllerAnimated:player];

    return;    
4

6 に答える 6

2

iOS 6 では、自動回転動作のメカニズムが変更されているため、iOS 6 デバイスでテストする場合は、少し追加の作業が必要になります。ビュー コントローラーで、次のメソッドを追加します。

-(NSInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
于 2013-03-25T16:03:28.563 に答える
1

いくつかのアプローチを利用できます。おそらく、最も単純で最も制御しやすいのは、 のサブクラス化ですMPMoviePlayerViewController

アプリですべてのインターフェイスの向きをサポートすることから始めます( をapp-info.plist参照)。次に、iOS 6 とそれ以前のオペレーティング システムの両方の方法で、リスト ビュー(だと仮定します) を縦向きに制限します。MyListViewController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 return UIInterfaceOrientationMaskPortrait;
}

- (NSUInteger) supportedInterfaceOrientations {
 return(UIInterfaceOrientationMaskPortrait);
}

- (BOOL) shouldAutorotate {
 return FALSE;   
}

次に、 から派生した という新しい Objective C クラスを作成しMPMoviePlayerViewControllerますMyMoviePlayerViewController。ここにありMyMoviePlayerViewController.hます:

#import <MediaPlayer/MediaPlayer.h>

@interface MyMoviePlayerViewController : MPMoviePlayerViewController

@end

そして、ここにありますMyMoviePlayerViewController.m

#import "MyMoviePlayerViewController.h"

@interface MyMoviePlayerViewController ()
@end

@implementation MyMoviePlayerViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 return YES;
}

- (NSUInteger) supportedInterfaceOrientations {
 return(UIInterfaceOrientationMaskAll);
}

- (BOOL) shouldAutorotate {
 return TRUE;    
}

-(id)initWithContentURL:(NSURL *)contentURL {
 UIGraphicsBeginImageContext(CGSizeMake(1,1));
 self = [super initWithContentURL:contentURL];
 UIGraphicsEndImageContext();
 if (self) {
    self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [[NSNotificationCenter defaultCenter] removeObserver:self
            name:MPMoviePlayerPlaybackDidFinishNotification
            object:[self moviePlayer]];
        [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(movieFinishedCallback:)
            name:MPMoviePlayerPlaybackDidFinishNotification
            object:[self moviePlayer]];
 }
 return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
[[self moviePlayer] setFullscreen:YES animated:NO];
[self moviePlayer].controlStyle = MPMovieControlStyleDefault;
}

- (void)movieFinishedCallback:(NSNotification*)notification {
    MPMoviePlayerController *moviePlayer = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
        name:MPMoviePlayerPlaybackDidFinishNotification
        object:moviePlayer];
    self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end

次に、に追加しMyListViewController.hます:

#import "MyMoviePlayerViewController.h"

ではMyListViewController.m、次を使用します。

MyMoviePlayerViewController *player =[[MyMoviePlayerViewController alloc]
    initWithContentURL:URLWithString:[[main_data objectAtIndex:indexPath.row]
    objectForKey:@"url"]]];
[self presentViewController:player animated:YES completion:nil];

もちろん、特定のニーズに合わせて設定 (アニメーション スタイル、表示するコントロールなど) を微調整できます。

于 2013-03-29T12:13:31.453 に答える
0

これをリストビューコントローラーに実装します

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationPortrait ;
}

-アヌープ

于 2013-03-28T07:55:27.390 に答える
0

[UIViewController attemptRotationToDeviceOrientation]ビデオ コントローラーが非表示のときに電話をかけるとどうなりますか?

于 2013-03-25T16:27:40.730 に答える
0

コードの下にコードを書く必要があると思います- (void)movieFinishedCallback:(NSNotification*)notification

- (void)movieFinishedCallback:(NSNotification*)notification 
{
    [self.view setFrame: CGRectMake(0, 0, 320, 480)];
    CGAffineTransform landscapeTransform;
    landscapeTransform = CGAffineTransformMakeRotation(270*M_PI/180.0f);
    landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
    [self.view setTransform: landscapeTransform];
}
于 2013-03-30T11:48:08.133 に答える
0

これを試して、

viewdidLoad メソッドで、アプリでの向きをサポートするために次の行を記述します。

//rotation
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:@"UIDeviceOrientationDidChangeNotification" object:nil];



#pragma mark -Rotation
//method for rotate your playerview, as user changes orientation
-(void)orientationChanged 
{
    NSLog(@"Orientation Changed..!!");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.35];
    if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait)  {
        playerView.transform = CGAffineTransformMakeRotation(0);
    }
    else if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortraitUpsideDown) {
        playerView.transform = CGAffineTransformMakeRotation(M_PI);
    }
    else if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)  {
        playerView.transform = CGAffineTransformMakeRotation(M_PI+(M_PI/2));
    }
   else if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight)        {
        playerView.transform = CGAffineTransformMakeRotation(M_PI/2);
    }
    [UIView commitAnimations];
}

#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation:   (UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
#endif

// For Newer than IOS 6.
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate
{
    return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait);
}
#endif

これがお役に立てば幸いです., Thnak you..幸せなコーディング

于 2013-03-29T04:06:10.530 に答える