Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityIndicatorView Misaligned

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.
like image 983
Patrick Perini Avatar asked Apr 16 '26 18:04

Patrick Perini


1 Answers

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.

like image 190
XJones Avatar answered Apr 18 '26 12:04

XJones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!