IOS 8自定义键盘旋转处理,为横向键盘加载另一个xib文件
我正在寻找一种方法来处理来自iOS 8设备(iPhone 6)的旋转通知,以便为横向键盘加载不同的xib 我有几个纵向键盘,每一个都是从它的xib文件加载的,所有的都可以,但是我想为横向布局加载另一个xib文件,但还没有找到一个有效的解决方案 我已经尝试注册了许多其他答案中推荐的通知,但没有成功 我已经尝试了这里推荐的所有方法:,但是通过检测推荐的尺寸来确定我们是在风景区还是在肖像区仍然不起作用 添加一些使用的代码:IOS 8自定义键盘旋转处理,为横向键盘加载另一个xib文件,ios,landscape-portrait,custom-keyboard,ios8-extension,Ios,Landscape Portrait,Custom Keyboard,Ios8 Extension,我正在寻找一种方法来处理来自iOS 8设备(iPhone 6)的旋转通知,以便为横向键盘加载不同的xib 我有几个纵向键盘,每一个都是从它的xib文件加载的,所有的都可以,但是我想为横向布局加载另一个xib文件,但还没有找到一个有效的解决方案 我已经尝试注册了许多其他答案中推荐的通知,但没有成功 我已经尝试了这里推荐的所有方法:,但是通过检测推荐的尺寸来确定我们是在风景区还是在肖像区仍然不起作用 添加一些使用的代码: const int keyboardHeight = 375; const i
const int keyboardHeight = 375;
const int landscapekeyboardHeight = 200;
- (void)updateViewConstraints {
[super updateViewConstraints];
NSLayoutConstraint *_heightConstraintforLandscape
= [NSLayoutConstraint constraintWithItem:self.view
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:0.0
constant:landscapekeyboardHeight];
NSLayoutConstraint *_heightConstraintforPortrait
= [NSLayoutConstraint constraintWithItem:self.view
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:0.0
constant:keyboardHeight];
if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height)
{
// Portrait
[self.view removeConstraint: _heightConstraintforLandscape];
[self.view addConstraint: _heightConstraintforPortrait];
}
else
{
// Landscape
[self.view removeConstraint: _heightConstraintforPortrait];
[self.view addConstraint: _heightConstraintforLandscape];
self.inputView = (UIInputView*)self.LandscapeKeyboard;
}
}
我已经尝试了针对堆栈溢出提出的大多数解决方案,但对于iOS8自定义键盘没有任何效果。任何知道或见过有效解决方案的人都会非常棒。不要将此代码放在updateViewConstraints中
if([UIScreen mainScreen].bounds.size.width<[UIScreen mainScreen].bounds.size.height)
{
//肖像画
[self.view removeConstraint:_heightConstraintforLandscape];
[self.view addConstraint:_heightConstraintforPortrait];
}
其他的
{
//景观
[self.view removeConstraint:_heightConstraintforPortrait];
[self.view addConstraint:_heightConstraintforLandscape];
self.inputView=(UIInputView*)self.landscape键盘;
}
而是将其移动到viewDidLayoutSubviews,每当设备旋转时都会调用该子视图。您是否解决了问题?当方向发生更改时,会多次调用此方法!
// Request to turn on accelerometer and begin receiving accelerometer events
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleOrientationChangeWithNotification:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
- (void)handleOrientationChangeWithNotification:(NSNotification *)notification {
// Respond to changes in device orientation
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait)
{
self.inputView = (UIInputView*)self.Keyboard;
}
else
{
self.inputView = (UIInputView*)self.LandscapeKeyboard;
}
}
if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height)
{
// Portrait
[self.view removeConstraint: _heightConstraintforLandscape];
[self.view addConstraint: _heightConstraintforPortrait];
}
else
{
// Landscape
[self.view removeConstraint: _heightConstraintforPortrait];
[self.view addConstraint: _heightConstraintforLandscape];
self.inputView = (UIInputView*)self.LandscapeKeyboard;
}