UIAlertView 的文本字段不向上移动

发布于 2024-12-17 12:11:37 字数 1066 浏览 5 评论 0原文

我想显示一个提示以获取用户的用户名和密码。

我通过显示 UIAlertView 并将 UITextFields 添加为子视图来完成此操作。

最近,我将项目移至 XCode 4.2,并更新了所有项目设置。我的基础 SDK 设置为 iOS 5.0,部署目标设置为 4.0。

然后我注意到它只是针对 armv7 架构构建的,因此我将其更改为也包含 armv6,因为我也想支持 iPhone 3G。

执行此操作后,我注意到 UIAlertView 没有像以前一样向上移动,现在显示时它被键盘覆盖。我在Apple文档中读到,你不应该继承UIAlertViews(http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html),所以我改变了我做事的方式。这并没有解决问题。

我注意到,通过将“构建设置”-“仅构建活动架构”设置为“是”,我可以让它在我的手机(iPhone 4,即armv7架构)上工作。

我怀疑这个问题与尝试构建armv6有关(实际上,从我尝试构建的体系结构中删除它会给我正确向上移动的警报)。

我想我现在应该回答我的问题......我正在努力理解为什么会出现这样的情况。我在某处读到(现在找不到链接),在 iOS 4 及更高版本中向 UIAlertView 添加文本字段时,不需要手动向上移动警报。因为我至少是为 iOS 4 构建的,所以这不应该在两种架构上都工作吗?

另外,我怎样才能让它为armv6构建并且仍然有正确向上移动的警报?

编辑:也许我错了,但我注意到我的手机有 2 个实例,我可以将应用程序部署到其中。选择第一个并构建给我一个应用程序,其中 UIAlertViews 在应该向上移动时不会移动,但选择第二个可以使其正常工作。会发布屏幕截图,但我是新用户,所以我还没有必要的权限......

I want to display a prompt to get a user's username and password.

I am doing this by displaying a UIAlertView and adding UITextFields as subviews to it.

Recently I moved my project over to XCode 4.2 and I updated all my project settings. My base SDK is set to iOS 5.0 and my deployment target is set to 4.0.

I then noticed that it was only being built for armv7 architectures and so I changed that to include armv6 as well since I would like to support the iPhone 3G as well.

After doing this I noticed that the UIAlertView wasn't moving up as before and now it was being covered by the keyboard when it was displayed. I read in the Apple documentation that you shouldn't subclass UIAlertViews (http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html) and so I changed the way I was doing things. This didn't solve the problem.

I have noticed that I can get it to work on my phone (an iPhone 4, so armv7 architecture) by setting the Build Setting - "Build active architecture only" to YES.

I suspect that the problem is something to do with trying to build for armv6 (and indeed removing this from the architectures I am trying to build for gives me alerts which move up correctly).

I suppose I should get to my question now... I'm struggling to understand why this is behaving the way it is. I read somewhere (can't find the link now) that you don't need to move the alert up manually when adding a text field to a UIAlertView in iOS 4 and above. Since I am building for at least iOS 4 shouldn't this work on both architectures?

Also, how can I get it to build for armv6 and still have alerts which move up correctly?

Edit: Maybe I was wrong but I have noticed that I have 2 instances of my phone which I can deploy the app to. Selecting the first one and building gives me an app where the UIAlertViews don't move up when they should, but selecting the second one makes it work properly. Would post a screenshot, but I'm a new user and so I don't have the permissions necessary yet...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

z祗昰~ 2024-12-24 12:11:37

好吧,

我已经设法想出了一个可行的解决方案,并使 UIAlertView 处于正确的位置,但我仍然不完全确定问题的根本原因是什么。

我通过响应 UIAlertViewDelegate 方法 willPresentAlertView: 并执行以下操作来解决

- (void) willPresentAlertView: (UIAlertView *) alertView {

    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];

    if (keyWindow.center.y - alertView.center.y < 0.001f) {

        CGPoint center = [alertView center];
        center.y = center.y - 108.0f;
        [alertView setCenter:center];  
    }
}

它它检查 UIAlertView 是否位于屏幕中心并移动如果是,则将其向上(即,如果操作系统尚未计算出它的正确位置)。注意:如果您希望该功能同时适用于纵向和横向,您需要添加检查设备所在的特定方向,然后相应地调整警报向上移动的量。

Oki,

I've managed to come up with a solution which works and gets the UIAlertView to be in the correct position, but I'm still not entirely sure what the root cause of the problem is.

I solved it by responding to the UIAlertViewDelegate method willPresentAlertView: and doing the following

- (void) willPresentAlertView: (UIAlertView *) alertView {

    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];

    if (keyWindow.center.y - alertView.center.y < 0.001f) {

        CGPoint center = [alertView center];
        center.y = center.y - 108.0f;
        [alertView setCenter:center];  
    }
}

It checks whether the UIAlertView is in the center of the screen and moves it up if it is (i.e. if the OS hasn't already calculated the correct position of it). Note: You would need to add a check for which specific orientation the device is in and then adjust the amount the alert is moved up accordingly if you wanted this to work for both portrait and landscape orientations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文