Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
gz_video_player
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
蒋俊
gz_video_player
Commits
c63ca1f7
提交
c63ca1f7
authored
9月 13, 2023
作者:
jungleiOS
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复 iOS 16 不能强制旋转问题
上级
917a0248
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
112 行增加
和
7 行删除
+112
-7
README.md
README.md
+12
-0
AppDelegate.m
example/ios/Runner/AppDelegate.m
+4
-0
Info.plist
example/ios/Runner/Info.plist
+7
-7
OrientationPlugin+Hook.h
ios/Classes/OrientationPlugin+Hook.h
+16
-0
OrientationPlugin+Hook.m
ios/Classes/OrientationPlugin+Hook.m
+73
-0
没有找到文件。
README.md
浏览文件 @
c63ca1f7
...
...
@@ -13,3 +13,15 @@ For help getting started with Flutter development, view the
[
online documentation
](
https://flutter.dev/docs
)
, which offers tutorials,
samples, guidance on mobile development, and a full API reference.
## ios 16 旋转
若想在 iOS 16 上强制旋转生效
1.
保证 info.plist 表里 Supported interface orientations 不要四个方向都勾上
2.
请在 AppDelegate 中加入如下代码,允许所有旋转方向
```
js
-
(
UIInterfaceOrientationMask
)
application
:(
UIApplication
*
)
application
supportedInterfaceOrientationsForWindow
:(
UIWindow
*
)
window
{
return
UIInterfaceOrientationMaskAll
;
}
```
example/ios/Runner/AppDelegate.m
浏览文件 @
c63ca1f7
...
...
@@ -10,4 +10,8 @@
return
[
super
application
:
application
didFinishLaunchingWithOptions
:
launchOptions
];
}
-
(
UIInterfaceOrientationMask
)
application
:(
UIApplication
*
)
application
supportedInterfaceOrientationsForWindow
:(
UIWindow
*
)
window
{
return
UIInterfaceOrientationMaskAll
;
}
@end
example/ios/Runner/Info.plist
浏览文件 @
c63ca1f7
...
...
@@ -2,6 +2,8 @@
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
CADisableMinimumFrameDurationOnPhone
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
CFBundleDevelopmentRegion
<
/k
e
y
>
<
string
>
$
(
DEVELOPMENT_LANGUAGE
)<
/string
>
<
k
e
y
>
CFBundleDisplayName
<
/k
e
y
>
...
...
@@ -24,28 +26,26 @@
<
string
>
$
(
FLUTTER_BUILD_NUMBER
)<
/string
>
<
k
e
y
>
LSRequiresIPhoneOS
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
UIApplicationSupportsIndirectInputEvents
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
UILaunchStoryboardName
<
/k
e
y
>
<
string
>
LaunchScreen
<
/string
>
<
k
e
y
>
UIMainStoryboardFile
<
/k
e
y
>
<
string
>
Main
<
/string
>
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UISupportedInterfaceOrientations
~
ipad
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationPortraitUpsideDown
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationPortraitUpsideDown
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UIViewControllerBasedStatusBarAppearance
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
CADisableMinimumFrameDurationOnPhone
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
UIApplicationSupportsIndirectInputEvents
<
/k
e
y
>
<
tru
e
/
>
<
/
d
i
c
t
>
<
/plist
>
ios/Classes/OrientationPlugin+Hook.h
0 → 100644
浏览文件 @
c63ca1f7
//
// OrientationPlugin+Hook.h
// Runner
//
// Created by 蒋俊 on 2023/9/13.
//
#import "OrientationPlugin.h"
NS_ASSUME_NONNULL_BEGIN
@interface
OrientationPlugin
(
Hook
)
@end
NS_ASSUME_NONNULL_END
ios/Classes/OrientationPlugin+Hook.m
0 → 100644
浏览文件 @
c63ca1f7
//
// OrientationPlugin+Hook.m
// Runner
//
// Created by 蒋俊 on 2023/9/13.
//
#import "OrientationPlugin+Hook.h"
#import <objc/runtime.h>
@implementation
OrientationPlugin
(
Hook
)
+
(
void
)
load
{
Method
originalMethod
=
class_getInstanceMethod
(
self
,
NSSelectorFromString
(
@"forceOrientation:"
));
Method
swizzledMethod
=
class_getInstanceMethod
(
self
,
@selector
(
hook_forceOrientation
:
));
method_exchangeImplementations
(
originalMethod
,
swizzledMethod
);
}
-
(
void
)
hook_forceOrientation
:
(
NSString
*
)
orientation
{
// 若想在 iOS 16 上强制旋转生效
// 1.请在 AppDelegate 中加入如下代码,允许所有旋转方向
// 2.info.plist 表里 Supported interface orientations 不要四个方向都勾上
// - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
//
// return UIInterfaceOrientationMaskAll;
// }
if
(
@available
(
iOS
16
.
0
,
*
))
{
UIWindowSceneGeometryPreferencesIOS
*
perference
=
[[
UIWindowSceneGeometryPreferencesIOS
alloc
]
init
];
if
([
orientation
isEqualToString
:
@"DeviceOrientation.portraitUp"
])
{
perference
.
interfaceOrientations
=
UIInterfaceOrientationMaskPortrait
;
[
self
requestGeometryUpdateWithPreferences
:
perference
];
}
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.portraitDown"
])
{
perference
.
interfaceOrientations
=
UIInterfaceOrientationMaskPortraitUpsideDown
;
[
self
requestGeometryUpdateWithPreferences
:
perference
];
}
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.landscapeLeft"
])
{
perference
.
interfaceOrientations
=
UIInterfaceOrientationMaskLandscapeLeft
;
[
self
requestGeometryUpdateWithPreferences
:
perference
];
}
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.landscapeRight"
])
{
perference
.
interfaceOrientations
=
UIInterfaceOrientationMaskLandscapeRight
;
[
self
requestGeometryUpdateWithPreferences
:
perference
];
}
else
{
perference
.
interfaceOrientations
=
UIInterfaceOrientationMaskPortrait
;
[
self
requestGeometryUpdateWithPreferences
:
perference
];
}
}
else
{
if
([
orientation
isEqualToString
:
@"DeviceOrientation.portraitUp"
])
{
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationPortrait
)
forKey
:
@"orientation"
];
}
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.portraitDown"
])
{
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationPortraitUpsideDown
)
forKey
:
@"orientation"
];
}
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.landscapeLeft"
])
{
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationLandscapeLeft
)
forKey
:
@"orientation"
];
}
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.landscapeRight"
])
{
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationLandscapeRight
)
forKey
:
@"orientation"
];
}
else
{
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationUnknown
)
forKey
:
@"orientation"
];
}
}
}
-
(
void
)
requestGeometryUpdateWithPreferences
:
(
UIWindowSceneGeometryPreferences
*
)
geometryPreferences
API_AVAILABLE
(
ios
(
16
.
0
)){
UIWindowScene
*
windowScene
=
(
UIWindowScene
*
)[[[
UIApplication
sharedApplication
]
connectedScenes
]
allObjects
].
firstObject
;
[
UIViewController
attemptRotationToDeviceOrientation
];
[
windowScene
requestGeometryUpdateWithPreferences
:
geometryPreferences
errorHandler
:
^
(
NSError
*
_Nonnull
error
)
{
NSLog
(
@"error--%@"
,
error
);
}];
UIWindow
*
keyWindow
=
[
UIApplication
sharedApplication
].
keyWindow
;
if
(
keyWindow
!=
NULL
)
{
[
keyWindow
.
rootViewController
setNeedsUpdateOfSupportedInterfaceOrientations
];
}
}
@end
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论