Bellow我有一些代码放在我的 AppDelegate.h& .M 即可。此代码检测我的MPMoviePlayerController何时进入全屏并通过通知退出全屏。调用通知后,它会将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 allowRotation;
- (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;
}
}
答案 0 :(得分:0)
当UI布局在开始时完成时调用接口旋转调用,并且稍后动态更改它不会改变方向。