HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS 8横向纵向模式下的自定义键盘大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_874_1@
我想在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];
}

但它不起作用.我该怎么办

解决方法

willRotateToInterfaceOrientation:duration:

在iOS 8中已弃用.请尝试使用

viewWillTransitionToSize:withTransitionCoordinator:

iOS Developer Library: viewWillTransitionToSize

函数为您提供对容器视图的新大小和转换协调器的引用.然后,您可以将键盘大小调整为新的屏幕尺寸.

还有一个附加到过渡协调器的功能,允许您在屏幕旋转时为视图设置动画和/或在屏幕旋转后完成功能块.

iOS Developer Library: UIViewControllerTransitionCoordinator

animateAlongsideTransition:completion:

animateAlongsideTransitionInView:animation:completion:

至于您的原始问题,您是否在设置约束后尝试在视图上调用layoutIfNeeded?

大佬总结

以上是大佬教程为你收集整理的iOS 8横向纵向模式下的自定义键盘全部内容,希望文章能够帮你解决iOS 8横向纵向模式下的自定义键盘所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。