Ios 检测UIInputViewController子类中的旋转。键盘分机
我一直在开发自定义键盘扩展,我需要在设备旋转后以编程方式更新一些约束。我一直试图在UIInputViewController子类中检测用户界面旋转,但没有成功。设备旋转时不调用以下方法:Ios 检测UIInputViewController子类中的旋转。键盘分机,ios,objective-c,ios8,uideviceorientation,ios8-extension,Ios,Objective C,Ios8,Uideviceorientation,Ios8 Extension,我一直在开发自定义键盘扩展,我需要在设备旋转后以编程方式更新一些约束。我一直试图在UIInputViewController子类中检测用户界面旋转,但没有成功。设备旋转时不调用以下方法: -(void)将TransitionOnTraitCollection:(UITraitCollection*)使用TransitionCoordinator:(id)coordinator新建集合{ NSLog(“方向改变”); } -(void)视图将转换大小:(CGSize)带有转换协调器的大小:(id)
-(void)将TransitionOnTraitCollection:(UITraitCollection*)使用TransitionCoordinator:(id)coordinator新建集合{
NSLog(“方向改变”);
}
-(void)视图将转换大小:(CGSize)带有转换协调器的大小:(id)协调器{
NSLog(“方向改变”);
}
我还尝试观察UIDeviceOrientationIDChangeNotification
,但它也不起作用
有人知道如何在UIInputViewController中检测旋转吗?看起来苹果没有向UIInputViewController提供此API方法
如果设备宽度大于
视图中的设备高度,则可以推断设备方向。如果正确,则将显示-这些方法不会在键盘扩展的UIInputViewController子类中调用(不确定其他扩展类型)
您需要覆盖viewdilayoutsubviews
例如,如果要在设备旋转时更新键盘UICollectionView子视图的布局,可以执行以下操作:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.keyboard.collectionView performBatchUpdates:nil completion:nil];
}
在您的情况下,您可以在ViewDidLayoutSubView中检查设备的方向,然后适当地应用/修改约束。Swift 4.2
override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
let screen = UIScreen.main.bounds
if screen.width < screen.height {
print("!!! portrait")
} else {
print("!!! landspace")
}
}
重写函数didRotate(来自fromInterfaceOrientation:UIInterfaceOrientation){
let screen=UIScreen.main.bounds
如果屏幕宽度<屏幕高度{
打印(!!!肖像)
}否则{
打印(!!!陆地空间)
}
}
IOS10中的
视图将转换大小
在
UIInputViewController中触发。