在iOS上使用屏幕键盘定位子类UIAlertView窗口 [英] positioning subclassed UIAlertView window with onscreen keyboard on iOS

查看:69
本文介绍了在iOS上使用屏幕键盘定位子类UIAlertView窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用子类UIAlertView窗口作为我的应用程序中的登录提示(我知道它违反Apple指南,但它不会提交给appstore,所以这不是问题)。



添加文本字段并在屏幕上定位窗口的代码如下所示:

   - (id)initWithTitle :(NSString *)title delegate:(id)委托
{
if(self = [super initWithTitle:title message:@\ n\\\
\ ndelegate:delegate cancelButtonTitle:@ 取消otherButtonTitles:@Login,nil]){
UITextField * loginTF = [[UITextField alloc] initWithFrame:CGRectMake(12.0,55.0,260.0,25.0)];
//删除了代码清晰度的文本字段设置
[self addSubview:loginTF];
self.loginTextField = loginTF;
[loginTF发布];

UITextField * passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(12.0,85.0,260.0,25.0)];
//删除了代码清晰度的文本字段设置
[self addSubview:passwordTF];
self.passwordTextField = passwordTF;
[passwordTF发布];

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0,90.0);
[self setTransform:translate];
}

返回自我;
}

问题在于 setTransform 在iOS 3.x上调用:





- 没有 setTransform :窗口在屏幕上水平和垂直居中显示,屏幕键盘部分显示在它上面 - 因此整个窗口不可见

- 带 setTransform :窗口显示高出90个像素,因此在显示屏幕键盘时整个可见。 iOS 4.x上的

然而:

- 没有 setTransform :显示窗口非常好(在屏幕键盘上方可见)

- 带 setTransform :窗口部分显示在屏幕的顶部边框上方(90像素太高) )。



这个问题的最佳解决方案是什么?检测iOS版本并有条件地调用 setTransform ?或者它是太丑陋的黑客并且有一些更好的方法?

解决方案

因为iOS 4已经发布用于较新的设备(和iOS) 4.2 for iPad就在附近),我建议将Base SDK设置为最新版本的iOS 4,并使用此版本编译您的应用程序。但是,如果您希望您的应用程序可供原始iPhone和iPod Touch用户使用,则有条件地使用 setTransform 方法是最好的方法。


I'm using subclassed UIAlertView window as a login prompt in my application (I know it's against Apple guidelines but it will not be submitted to the appstore so it's not a problem).

The code to add text fields and position the window on screen looks like this:

- (id)initWithTitle:(NSString *)title delegate:(id)delegate
{
    if (self = [super initWithTitle:title message:@"\n\n\n" delegate:delegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Login", nil]) {
        UITextField *loginTF = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 55.0, 260.0, 25.0)];
        // text field settings removed for code clarity 
        [self addSubview:loginTF];
        self.loginTextField = loginTF;
        [loginTF release];

        UITextField *passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
        // text field settings removed for code clarity
        [self addSubview:passwordTF];
        self.passwordTextField = passwordTF;
        [passwordTF release];

        CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 90.0); 
        [self setTransform:translate];
    }

    return self;
}

The problem is with setTransform call:

on iOS 3.x:
- without setTransform: The window is displayed centered horizontally and vertically on the screen, with onscreen keyboard displayed partially on top of it - so the whole window is not visible
- with setTransform: The window is displayed 90 pixels higher, so it is whole visible with onscreen keyboard displayed.

on iOS 4.x however:
- without setTransform: The window is displayed perfectly fine (visible above the onscreen keyboard)
- with setTransform: The window is displayed partially above the top border of the screen (90 pixels too high).

What would be the best solution for this issue? Detecting iOS version and calling setTransform conditionally? Or it's too ugly hack and there is some better way?

解决方案

Because iOS 4 has been released for the newer devices (and iOS 4.2 for iPad is right around the corner), I would recommend setting the Base SDK to the latest version of iOS 4 and compiling your application with this version. However, if you want your application to be available to original iPhone and iPod Touch users, conditionally using the setTransform method is the best way.

这篇关于在iOS上使用屏幕键盘定位子类UIAlertView窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆