UIActivityIndi​​catorView 未对齐

发布于 2024-12-18 17:29:47 字数 896 浏览 2 评论 0原文

我有 UIActivityIndi​​catorView 在 XIB 中水平居中。

XIB

在 iOS 4(模拟器)中,指示器默认为大白(iOS 5 中引入的颜色属性),这很好。奇怪的是它也是偏移的。

iOS4

我最初的假设是 XIB 有问题(或类似的问题)。然而,在iOS 5(模拟器、iPhone 4)中,它运行得很好。

iOS5

从 iOS 4 到 iOS 5,关于 UIActivityIndi​​catorView 的唯一变化是添加 color 属性,我很困惑。我知道这里可能没有足够的信息来推断出确切的问题。我更关心从哪里开始调试,并欢迎任何关于我可以提供哪些进一步信息的建议。

更多信息

  • iPad 将指示器加载到可靠的位置,仅在 iOS 4 和 iOS 5 之间更改颜色。
  • 我有两个静态原点 (portPoint = (x, y); landPoint = (w, z);),我手动设置旋转。当应用程序加载时,指示器的原点(正确)是 portPoint (我已通过 NSLog 验证),尽管视觉上未对齐。当我旋转到横向时,原点正确(视觉上和数据方面)设置为landPoint。当我向后旋转时,原点正确(视觉上和数据方面)设置为 portPoint,从而解决了问题。

I have UIActivityIndicatorView centered horizontally in a XIB.

XIB

In iOS 4 (Simulator), the indicator defaults to Large White (the color property being introduced in iOS 5), which is fine. The weird part is that it is also offset.

iOS4

My initial assumption was that something was wrong with the XIB (or something to that effect). However, in iOS 5 (Simulator, iPhone 4), it works perfectly.

iOS5

Seeing as how the only thing changed from iOS 4 to iOS 5 regarding UIActivityIndicatorViews was the addition of the color property, I'm stumped. I'm aware that there's probably nowhere near enough information here to deduce the exact problem. I'm more concerned about where to start debugging, and welcome any suggestions as to what further information I could supply.

Further Information:

  • The iPad loads the indicator in a reliable position, only changing colors between iOS 4 and iOS 5.
  • I have two static origin points (portPoint = (x, y); landPoint = (w, z);), that I manually set on rotation. When the app loads, the indicator's origin is (correctly) portPoint (which I've verified via NSLog), despite being visually misaligned. When I rotate to landscape, the origin correctly (visually and data-wise) sets to landPoint. When I rotate back, the origin correctly (visually and data-wise) sets to portPoint, thus resolving the issue.

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

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

发布评论

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

评论(3

难忘№最初的完美 2024-12-25 17:29:47

你是对的,没有看到你的代码,我无法判断是否发生了其他事情,但将视图置于超级视图中并在设备旋转时保持这一点相当简单。试试这个:

  1. 确保 UIActivityIndi​​catorViewautoResizingMask 设置为 UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleTopMargin UIViewAutoresizingFlexibleBottomMargin

  2. 将活动指示器放置在其超级视图的中心,无论是在 XIB 文件中还是在 viewDidLoad

  3. 不要更改旋转时活动指示器的框架,它应该自动保持居中

如果上述方法不能解决问题,请发布一些代码以及相关视图的 autoResizingMaskcontentMode 值。

You're right that w/o seeing your code I can't tell if anything else is going on but centering a view within a superview and maintaining that when the device rotates is fairly simple. Try this:

  1. Make sure the autoResizingMask of the UIActivityIndicatorView is set to UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin

  2. Position the activity indicator in the center of its superview, either in the XIB file or in viewDidLoad

  3. Don't change the frame of the activity indicator on rotation, it should stay centered automatically

If the above doesn't fix it, post some code along with the autoResizingMask and contentMode values for relevant views.

安静被遗忘 2024-12-25 17:29:47

它看起来确实就像设备处于横向放置一样。当视图大小或方向改变时,检查是否正确地重新定位它。

It sure looks like its positioned as if the device were in landscape. Check to see that you reposition it properly when the view size or orientation changes.

雨后彩虹 2024-12-25 17:29:47

想法:

1/您的视图(活动指示器超级视图)比您的显示器大(自动调整大小掩码错误?xib plist 中的值错误?)或者它在其超级视图内的位置错误。

2/ 自动调整蒙版大小设置不正确。对于活动指示器,它应该是要

(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin)

调试它,请尝试将日志记录到 viewDidAppear 中。获取活动指示器的中心 (CGPoint) 并使用 UIView 方法将其转换为顶部视图坐标(例如 [UIView ConvertPoint:fromView:])。该位置应该与您在屏幕上看到的位置相同。

如果不是,则存在一些更大的问题,可能与动画状态有关。
否则,您应该能够找到将活动指示器转换到这个奇怪位置的视图。记录层次结构中所有视图的框架。

检查您是否在正确的位置记录了信息,并且在记录后没有更改视图位置。

Ideas:

1/ Your view (activity indicator superview) is bigger than your display (bad autoresizing mask? bad values in xib plist?) or it has bad position inside its superview.

2/ Autoresizing masks are not set correctly. For the activity indicator it should be

(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin)

To debug this, try to put logging into viewDidAppear. Get the center (CGPoint) of your activity indicator and use UIView methods to convert it to your top view coordinates (e.g. [UIView convertPoint:fromView:]). This position should be the same as the one you see on the screen.

If it's not, there is some bigger problem, possibly connected with animation states.
Otherwise you should be able to find the view which translates your activity indicator to this weird position. Log the frames of all views in your hierarchy.

Check that you log the information at the right place and you don't change view positions after the logging.

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