我正在设置一个带有文本字段的警报,以便玩家可以输入他们的名字以获得高分.游戏以横向模式定向,但是当我打电话显示警报时,警报会以纵向模式弹出,同时显示两个键盘,一个是横向模式,另一个是横向模式的景观尺寸.这是我用来设置警报对话框的代码:
UIAlertView* dialog = [[[UIAlertView alloc] init] retain];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];
[dialog addTextFieldWithValue:@"name" label:@""];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
如何以横向方式制作警报节目并防止其显示两个键盘?
谢谢,
本
最佳答案 对于那些可能关心的人来说,这是一个有效的解决方案,可以在横向模式下正常工作:
UIAlertView* dialog = [[[UIAlertView alloc] init] retain];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];
确保你已经创建了UITextField * nameField;在.h文件中,您可以通过以下操作获取用户键入的文本:
inputText = [nameField text];
在 – (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex方法.