Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS Configure rotation. 旋转的配置看这里 (2.6.5版本及以后) #148

Closed
changsanjiang opened this issue Sep 10, 2019 · 28 comments
Closed

Comments

@changsanjiang
Copy link
Owner

changsanjiang commented Sep 10, 2019

v2.6.5版本及以后需要在项目中添加旋转的配置. 遇到点击无法触发旋转的请按照以下步骤进行配置.

@changsanjiang
Copy link
Owner Author

changsanjiang commented Sep 10, 2019

Demo.zip

Step 1(第一步):

image.png


Step 2(第二步):

image.png

Step 3(第三步):

@implementation UIViewController (RotationControl)
- (BOOL)shouldAutorotate { 
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

@end


@implementation UITabBarController (RotationControl)
- (UIViewController *)sj_topViewController {
    if ( self.selectedIndex == NSNotFound )
        return self.viewControllers.firstObject;
    return self.selectedViewController;
}

- (BOOL)shouldAutorotate {
    return [[self sj_topViewController] shouldAutorotate];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return [[self sj_topViewController] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [[self sj_topViewController] preferredInterfaceOrientationForPresentation];
}
@end

@implementation UINavigationController (RotationControl)
- (BOOL)shouldAutorotate {
    return self.topViewController.shouldAutorotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return self.topViewController.supportedInterfaceOrientations;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return self.topViewController.preferredInterfaceOrientationForPresentation;
}

- (nullable UIViewController *)childViewControllerForStatusBarStyle {
    return self.topViewController;
}

- (nullable UIViewController *)childViewControllerForStatusBarHidden {
    return self.topViewController;
}
@end

@changsanjiang changsanjiang changed the title iOS 旋转的配置(2.6.5版本及以后) iOS 旋转的配置看这里 (2.6.5版本及以后) Sep 10, 2019
@changsanjiang changsanjiang pinned this issue Sep 10, 2019
@szdkkk
Copy link

szdkkk commented Sep 11, 2019

self.windowLevel = UIApplication.sharedApplication.keyWindow.windowLevel + 1;// UIWindowLevelNormal;
SJFullscreenModeWindow的windowLevel属性应该设置成比host app的keyWindow高,不然全屏之后是看不到播放window的。

@szdkkk
Copy link

szdkkk commented Sep 11, 2019

另外还有个问题,UITabBarController的某一个子tab包含播放器的时候,如果正在显示的tab是不包含播放器,旋转屏幕也会呼出全屏播放器界面。

@changsanjiang
Copy link
Owner Author

@szdkkk 调一下这个几个方法试试.
image

@changsanjiang changsanjiang changed the title iOS 旋转的配置看这里 (2.6.5版本及以后) iOS (Set up Rotation)旋转的配置看这里 (2.6.5版本及以后) Oct 20, 2019
@changsanjiang changsanjiang changed the title iOS (Set up Rotation)旋转的配置看这里 (2.6.5版本及以后) iOS Set up Rotation. 旋转的配置看这里 (2.6.5版本及以后) Oct 20, 2019
@changsanjiang changsanjiang changed the title iOS Set up Rotation. 旋转的配置看这里 (2.6.5版本及以后) iOS Configure rotation. 旋转的配置看这里 (2.6.5版本及以后) Oct 20, 2019
@m3u8playlist
Copy link

这样配置是不是app界面只能竖屏了

@changsanjiang
Copy link
Owner Author

横屏的App参考ipad Demo

@DarielChen
Copy link

Snip20200411_61

横屏Demo有问题,这个问题项目中也存在,就是当非横屏状态下app退到后台,然后再回到前台app再切换屏幕方向,会出现上述状态

@changsanjiang
Copy link
Owner Author

test

@DarielChen 奇怪了...我这里没出现这个bug... 可以提供一下详细的操作吗, 或者加QQ群录个小视频看看

@DarielChen
Copy link

DarielChen commented Apr 12, 2020

OC_demo.zip

我这个问题主要是按照你提供的方式配置了全屏的操作,但我想禁止自动横屏,只在点击全屏按钮时才能横屏但不行,你能帮我看下么,到底啥问题哦

@implementation UIViewController (RotationControl)
- (BOOL)shouldAutorotate { 
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

是这两个方法不调用?好奇怪

@Ccalary
Copy link

Ccalary commented Apr 23, 2020


DarielChen :我这个问题主要是按照你提供的方式配置了全屏的操作,但我想禁止自动横屏,只在点击全屏按钮时才能横屏但不行,你能帮我看下么,到底啥问题哦

同求解

@DarielChen
Copy link

@Ccalary 用交换方法重新实现一下我上面列的两个方法

@Ccalary
Copy link

Ccalary commented Apr 24, 2020

@DarielChen 交换方法重新实现,不太明白,可以详细说说吗

@DarielChen
Copy link

@Ccalary

+ (void)load{
    NSError *err;
    [self jr_swizzleMethod:@selector(shouldAutorotate) withMethod:@selector(tm_shouldAutorotate) error:&err];
    [self jr_swizzleMethod:@selector(supportedInterfaceOrientations) withMethod:@selector(tm_supportedInterfaceOrientations) error:&err];
}

- (BOOL)tm_shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientationMask)tm_supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

@YangYueFan
Copy link

第一次全屏动画卡顿是什么原因,跟没有动画一样,后面都正常

@chocolate1128
Copy link

你好,我设置了自动选择
当播放竖屏拍摄的视频时(Width<Height), 在点击全屏按钮之后, 没有问题。
当播放横屏拍摄的视频时(Width>Height), 在点击全屏按钮之后, 全屏播放的view没有出现,或者说是有一层透明的view盖在APP界面的上面,所有手势都没用,有遇到过这个情况吗

@changsanjiang
Copy link
Owner Author

@chocolate1128 前三步的配置需添加上

@changsanjiang
Copy link
Owner Author

@YangYueFan 可能是第一次旋转时, 执行的任务比较多卡顿了, 后续我再看看

@chocolate1128
Copy link

测试全屏播放.mp4.zip
就是这样的情况,也不知道哪里出了问题

@chocolate1128
Copy link

找到问题了,有一个分类把supportedInterfaceOrientationsForWindow重写了,现在没问题了

@H4AER
Copy link

H4AER commented May 12, 2020

配置完旋转的时候不走下面的两个方法 @changsanjiang
@implementation UIViewController (RotationControl)

  • (BOOL)shouldAutorotate {
    return NO;
    }

  • (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
    }

@lianxiaoshuo
Copy link

OC_demo.zip

我这个问题主要是按照你提供的方式配置了全屏的操作,但我想禁止自动横屏,只在点击全屏按钮时才能横屏但不行,你能帮我看下么,到底啥问题哦

@implementation UIViewController (RotationControl)
- (BOOL)shouldAutorotate { 
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

是这两个方法不调用?好奇怪

同问这个

@changsanjiang
Copy link
Owner Author

@lianxiaoshuo TestController 加上这个

@implementation TMTestController

- (BOOL)shouldAutorotate {
    return NO;
}

@end

@lianxiaoshuo
Copy link

OC_demo.zip

我这个问题主要是按照你提供的方式配置了全屏的操作,但我想禁止自动横屏,只在点击全屏按钮时才能横屏但不行,你能帮我看下么,到底啥问题哦

@implementation UIViewController (RotationControl)
- (BOOL)shouldAutorotate { 
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

是这两个方法不调用?好奇怪

  • (BOOL)shouldAutorotate {
    return NO;
    }在你的tablebar写上这句话就可以了

@changsanjiang
Copy link
Owner Author

这个调用是从 tabBar 到 nav 再到 vc, 一层一层传上来的. 当在某个 vc 实现了 shouldAutorotation 方法, 分类的方法就不会触发.

@lianxiaoshuo
Copy link

lianxiaoshuo commented Jul 16, 2020 via email

@chenshipeng
Copy link

点击旋转和自动旋转不是应该分开的吗?现在我按照这个配置了,点击全屏还是卡主了,页面其他的地方都不能点击了

@sauchye
Copy link

sauchye commented Jul 20, 2021

//修改按钮
SJEdgeControlLayer *sjControlLayer            = self.player.defaultEdgeControlLayer;
SJEdgeControlButtonItemAdapter *centerAdapter = sjControlLayer.centerAdapter;
SJEdgeControlButtonItemAdapter *bottomAdapter = sjControlLayer.bottomAdapter;

// 移除按钮
[centerAdapter removeItemForTag:SJEdgeControlLayerCenterItem_Replay];/// 重播
[centerAdapter reload];
[bottomAdapter removeItemForTag:SJEdgeControlLayerBottomItem_Full];/// 全屏

// 添加按钮
SJEdgeControlButtonItem *smallItem = [SJEdgeControlButtonItem.alloc initWithImage:[UIImage imageNamed:@"small_screen_icon"] target:self action:@selector(zoomAction) tag:1011];
[bottomAdapter addItem:smallItem];
[bottomAdapter reload];

// 修改事件
SJEdgeControlButtonItem *playItem = [bottomAdapter itemForTag:SJEdgeControlLayerBottomItem_Play];
[playItem removeAllActions];
[playItem addAction:[SJEdgeControlButtonItemAction actionWithHandler:^(SJEdgeControlButtonItemAction * _Nonnull action) {
    ////[weakSelf.navigationController popViewControllerAnimated:NO];
}]];

@dczjs
Copy link

dczjs commented Nov 22, 2021

ipad无法横屏全屏,只能竖屏全屏

@changsanjiang changsanjiang unpinned this issue Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests