我想在 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];
}
但它不起作用。我应该怎么办?