Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 检测UIInputViewController子类中的旋转。键盘分机_Ios_Objective C_Ios8_Uideviceorientation_Ios8 Extension - Fatal编程技术网

Ios 检测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)

我一直在开发自定义键盘扩展,我需要在设备旋转后以编程方式更新一些约束。我一直试图在UIInputViewController子类中检测用户界面旋转,但没有成功。设备旋转时不调用以下方法:

-(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中触发。