0

Bellow 我有一些代码放在我的AppDelegate.h & .m中。此代码检测我的 MPMoviePlayerController(s) 何时通过通知进入全屏和退出全屏。一旦通知被调用,它就会设置allowRotation为 yes,然后允许用户旋转视图。然而,一旦用户已激活全屏并且仍处于某个方向,播放器就会关闭,但会在用户在观看视频时放置的方向上留下视图。这是由于退出全屏通知被调用但-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window未被调用。所以它只会在用户旋转设备时重新旋转到端口速率。但我不希望这样,并希望它在通知被调用后立即旋转。有人可以帮忙吗?

这是我的代码:

。H

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic) BOOL allowRotation;


@end

.m @synthesize 允许旋转;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
    allowRotation = NO;
    return YES;
}

- (void) MPMoviePlayerDidExitFullscreen:(NSNotification*)notification {
    NSLog(@"calling1");
    self.allowRotation = NO;
}


- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
    NSLog(@"calling");
    self.allowRotation = YES;
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (self.allowRotation == YES) {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    else if (self.allowRotation == NO){
        NSLog(@"portrait");
    return UIInterfaceOrientationMaskPortrait;
    }

}
4

1 回答 1

0

当 UI 布局在开始时完成并在以后动态更改不会更改方向时,调用界面旋转调用。

于 2013-08-02T23:56:56.277 回答