【发布时间】:2014-09-01 12:09:47
【问题描述】:
我想在 iOS 8 中制作一个自定义键盘。我想在手机旋转到横向模式时更改它的大小。
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
if ((toInterfaceOrientation==UIInterfaceOrientationPortrait) || (toInterfaceOrientation==UIInterfaceOrientationPortrait))
{
[def setObject:@"No" forKey:@"LandScape"];
[def synchronize];
islandscapemode = NO;
NSLayoutConstraint *_heightConstraint =
[NSLayoutConstraint constraintWithItem: self.view
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 0.0
constant: 266];
[self.view addConstraint:_heightConstraint];
}
else
{
[def setObject:@"Yes" forKey:@"LandScape"];
[def synchronize];
NSLayoutConstraint *_heightConstraint =
[NSLayoutConstraint constraintWithItem: self.view
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 0.0
constant: 266];
[self.view addConstraint:_heightConstraint];
self.view.backgroundColor=[UIColor greenColor];
islandscapemode = YES;
}
// [self determineKeyboardNib:toInterfaceOrientation];
}
但它不起作用。我该怎么办?
【问题讨论】:
-
当它变成横向模式时,我应该怎么做才能减小视图的大小?
-
“它不起作用”是什么意思?键盘保持相同的大小?你有错误信息吗?设备在你手中爆炸,你用一只好手输入了这个问题?
-
您应该在 -[viewDidLoad] 中,将约束添加到视图并更改约束常量值,而不是添加会导致约束错误的新约束。在你的约束代码中,你应该设置超级视图来关闭自动调整大小
标签: ios ios8 landscape-portrait ios-app-extension custom-keyboard