我有一個應用程序的兩個ipad的iphones,ipad的用戶總是啓用橫向模式和iphone用戶的肖像,現在我想實現的是在iphone應用程序中使用AVPlayerViewController播放視頻,但自應用程序被鎖定在appdelegate裏面的肖像中,當我按下播放器上的全屏按鈕時,它將保持opn肖像模式我想使它成爲風景我嘗試了所有我在stackoverflow中找到的答案,但沒有運氣如何使任何想法這行得通 ?AVPlayerviewcontroller iOS目標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
文件中添加以下代碼。
目標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. AVPlayerViewController沒有「完成」按鈕目標C
- 2. 目標C IOS的新建?
- 3. 如何在IOS目標C
- 4. AVPlayer不播放音頻 - iOS 9,目標 - C
- 5. iOS - 在AVPlayerViewController頂部添加控件
- 6. iOS AVPlayerViewController不顯示播放控件
- 7. AVPlayerLayer VS AVPlayerViewController
- 8. 視頻無法播放目標c
- 9. 目標C:正在爲ios提供嗎?
- 10. 目標C/iOS版 - 物業類型上
- 11. UIActivityViewController顯示顯示ios的目標c
- 12. 按鈕不會禁用IOS目標C
- 13. Bing v7到v8遷移iOS目標C
- 14. 訪問聯繫人iOS目標c
- 15. 在iOS中添加Cloudinary Pod目標C
- 16. 內存泄漏IOS /目標C
- 17. 解析JSON的目標C(IOS)
- 18. iOS /目標C:代碼說明
- 19. 對於iOS如何在目標C
- 20. iOS目標中的多線程C
- 21. 目標c的iOS本地通知
- 22. ios facebook像目標c中的反應
- 23. IOS目標c的tableView搜索欄
- 24. iOS刪除按鈕 - 目標C
- 25. RxJava和iOS開發與目標C
- 26. AVPlayerViewController發出
- 27. 目標C與目標C++
- 28. iOS部署目標
- 29. IOS目標路徑
- 30. IOS如何AFNetworking添加到我的Xcode項目的目標C
我的答案是否適合您? –
不,它沒有。不管怎麼說,多謝拉。 –