我有一個應用程序的兩個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. 如果在iOS(目標c)
- 3. 目標C IOS的新建?
- 4. 目標C/IOS - AVAsset - 錯誤
- 5. 如何在IOS目標C
- 6. 認證ios 6目標c
- 7. AVPlayer不播放音頻 - iOS 9,目標 - C
- 8. iOS AVPlayerViewController不顯示播放控件
- 9. iOS - 在AVPlayerViewController頂部添加控件
- 10. ios AVPlayerViewController無法播放本地mp4
- 11. AVPlayerLayer VS AVPlayerViewController
- 12. 視頻無法播放目標c
- 13. AVPlayerViewController發出
- 14. didSelectRowAtIndexPath中的DetailViewController - iOS iPhone 5目標c
- 15. IOS目標C祖父母代表
- 16. 無法接收remoteControlReceivedWithEvent - 目標c - ios
- 17. WSDL/XML解析iOS目標C
- 18. 目標C IOS類變量叫做 「ID」
- 19. CGAffineTransformRotate和M_PI不一致(目標C,iOS)
- 20. iOS中的UINotification問題/目標C
- 21. 解析JSON的目標C(IOS)
- 22. 在NSObject中取消目標c塊iOS
- 23. 目標C:正在爲ios提供嗎?
- 24. iOS目標中的多線程C
- 25. 在iOS中添加Cloudinary Pod目標C
- 26. 對於iOS如何在目標C
- 27. 訪問聯繫人iOS目標c
- 28. dismissViewControllerAnimated導致黑屏ios目標c
- 29. RxJava和iOS開發與目標C
- 30. UIActivityViewController顯示顯示ios的目標c
我的答案是否適合您? –
不,它沒有。不管怎麼說,多謝拉。 –