私は両方のipadのiphone、ipadのユーザーのためのアプリケーションを持っています常にランドスケープモードが有効になり、iphoneユーザーのための肖像画、今私が達成しようとしているものは、私はAVPlayerViewControllerアプリケーションはappdelegate内の肖像画でロックされています。プレーヤーのフルスクリーンボタンを押すと、それはちょうどopnポートレートモードに留まります。私はそれを風景にしたいです。私はstackoverflowで見つけたすべての答えを試しましたが、それは動作しますか?AVPlayerviewcontroller ios objective c
0
A
答えて
0
私は良い習慣を知らないが、これは毎秒呼び出されるメソッドを作っNSTimerでこの問題を解決し私がしたこと:
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(yourMethod) userInfo:nil repeats:YES];
-(void)yourMethod{
if(!_fullscreen){
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}else{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
} }
_fullscreenは、AVplayerがフルスクリーン表示または通常表示に切り替わるときに変更されるフラグです。
AVplayerの状態を追跡するために、Observer @ "bounds"を使用して、AVPlayerの画面のサイズを確認しました。
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context {
if (object == self.playerViewController.contentOverlayView) {
if ([keyPath isEqualToString:@"bounds"]) {
CGRect oldBounds = [change[NSKeyValueChangeOldKey] CGRectValue], newBounds = [change[NSKeyValueChangeNewKey] CGRectValue];
BOOL wasFullscreen = CGRectEqualToRect(oldBounds, [UIScreen mainScreen].bounds), isFullscreen = CGRectEqualToRect(newBounds, [UIScreen mainScreen].bounds);
if (isFullscreen && !wasFullscreen) {
if (CGRectEqualToRect(oldBounds, CGRectMake(0, 0, newBounds.size.height, newBounds.size.width))) {
NSLog(@"rotated fullscreen");
}
else {
NSLog(@"entered fullscreen");
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
}else{
_fullscreen = YES;
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
}
}
else if (!isFullscreen && wasFullscreen) {
NSLog(@"exited fullscreen");
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
}else{
_fullscreen = NO;
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
}
}
}}
0
AppDelegate.m
ファイルに下記のコードを追加してください。
のObjective C
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
#define supportedInterfaceOrientationsReturnType NSUInteger
#else
#define supportedInterfaceOrientationsReturnType UIInterfaceOrientationMask
#endif
- (supportedInterfaceOrientationsReturnType)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)windowx
{
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[AVPlayerViewController class]]
)
{
if ([self.window.rootViewController presentedViewController].isBeingDismissed)
{
return UIInterfaceOrientationMaskPortrait;
}else{
return UIInterfaceOrientationMaskAll;
}
}
}
スウィフト
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
let supportedInterfaceOrientationsReturnType = NSUInteger
#else
let supportedInterfaceOrientationsReturnType = .mask
#endif
func application(_ application: UIApplication, supportedInterfaceOrientationsFor windowx: UIWindow) -> supportedInterfaceOrientationsReturnType {
if (self.window!.rootViewController!.presented! is AVPlayerViewController) {
if self.window!.rootViewController!.presented!.isBeingDismissed() {
return .portrait
}
else {
return .all
}
}
}
関連する問題
- 1. Objective C(iOS 8)
- 2. iOSでObjective-C
- 3. アニメーションios objective-c
- 4. Objective Cの - IOS
- 5. RLMResults:allObjectsクラッシュ(iOS Objective-C)
- 6. iOS Objective-C required reading
- 7. iOS objective c substringToIndexクラッシュ
- 8. は、iOS Objective Cの
- 9. iOS Objective-Cでカウントダウン
- 10. IOS/Objective-C:レイジーロードUILabel
- 11. のObjective CのiOSプロジェクト+ Cocoapods
- 12. のObjective-C/iOSのは -
- 13. のiOS Objective-CのUIBarButtonItemセットセレクタ
- 14. JSON to UITableView IOS Objective-C
- 15. iOS Google DocsのObjective-Cラッパー
- 16. iOS QuickAction用のObjective-Cコード
- 17. iosロケーショントラッカーの問題(objective-c)
- 18. WKWebViewのiOS Objective-C LocalStore
- 19. iOS Objective-Cブロックコールバックの問題
- 20. のiOS Objective-CのUIBarButtonItemアクション
- 21. IOS/Objective-C:メインスレッドに戻る
- 22. Box API認証 - Objective-c iOS
- 23. iOSの - Objective Cの - プロパティ
- 24. Objective-CのSUPERとは - iOS
- 25. 方法のiOS Objective-Cの
- 26. Protobuf対JSON - Objective-C/iOS
- 27. iOS、swift、objective C、UserNotificationCenter、NSNotificationCenter
- 28. AVPlayerViewController黒い画面のiOS 11
- 29. IOS Objective CのARC変換問題
- 30. iOSでデコードする方法 - Objective C
私の答えはあなたのために働いていますか? –
いいえ、それはありませんでした。とにかく、ありがとう。 –