我无法在这里解释我的整个应用场景,因为解释起来有点复杂.所以,让我非常简单地提出这个问题.如何更改UIKeyBoard.i.e的框架.我希望UIKeyBoard向上旋转或平移90度以支持我的视图位置.
我有出路吗?解决方法 您无法更改默认键盘.但是,您可以通过将其设置为inputVIEw(例如,UITextFIEld)来创建用作键盘替换的自定义UIVIEw.
虽然创建自定义键盘需要一些时间,但它适用于较旧的iOS版本(UITextFIEld上的inputVIEw可在iOS 3.2及更高版本中使用)并支持物理键盘(如果连接了键盘,键盘会自动隐藏).
以下是创建垂直键盘的示例代码:
接口:
#import <UIKit/UIKit.h>@interface CustomKeyboardVIEw : UIVIEw@property (nonatomic,strong) UIVIEw *innerinputVIEw;@property (nonatomic,strong) UIVIEw *underlayingVIEw;- (ID)initForUnderlayingVIEw:(UIVIEw*)underlayingVIEw;@end
执行:
#import "CustomKeyboardVIEw.h"@implementation CustomKeyboardVIEw@synthesize innerinputVIEw=_innerinputVIEw;@synthesize underlayingVIEw=_underlayingVIEw;- (ID)initForUnderlayingVIEw:(UIVIEw*)underlayingVIEw{ // Init a CustomKeyboardVIEw with the size of the underlying vIEw // You might want to set an autoresizingMask on the innerinputVIEw. self = [super initWithFrame:underlayingVIEw.bounds]; if (self) { self.underlayingVIEw = underlayingVIEw; // Create the UIVIEw that will contain the actual keyboard self.innerinputVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0,100,underlayingVIEw.bounds.size.height)]; // You would need to add your custom buttons to this vIEw; for this example,it's just red self.innerinputVIEw.backgroundcolor = [UIcolor redcolor]; [self addSubvIEw:self.innerinputVIEw]; } return self;}-(ID)hitTest:(CGPoint)point withEvent:(UIEvent *)event { // A hitTest is executed whenever the user touches this UIVIEw or any of its subvIEws. ID hitTest = [super hitTest:point withEvent:event]; // Since we want to ignore any clicks on the "transparent" part (this vIEw),we execute another hitTest on the underlying vIEw. if (hitTest == self) { return [self.underlayingVIEw hitTest:point withEvent:nil]; } return hitTest;}@end
在某些UIVIEwController中使用自定义键盘:
- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; CustomKeyboardVIEw *customKeyboard = [[CustomKeyboardVIEw alloc] initForUnderlayingVIEw:self.vIEw]; textFIEld.inputVIEw = customKeyboard;}总结
以上是内存溢出为你收集整理的iphone – 如何在iOS中以编程方式更改UIKeyBoard的框架全部内容,希望文章能够帮你解决iphone – 如何在iOS中以编程方式更改UIKeyBoard的框架所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)