Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app gets completely misaligned when switching from 5 to 4.3 in simulator

I'm working on an app that is ideally targeted all the way down to iOS 3.2. Still, I am developing it on Lion and with the latest 5 sdk. As far as I know, I am not using any sdk 5 specific features. But:

on any devices with iOS 5 or the simulator (set to v.5), the app works just fine. on any devices with iOS 4.3 or below (and the same goes for the simulator set to v. 4.3), several things that have to do with view frames get misaligned.

For instance, here's 2 examples:

An activity indicator inside an alert view. Here's the code:

NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:fileRequest delegate:self];
  if(urlConnection) 
  {
    uistatusDialog = [[UIAlertView alloc] initWithTitle:(description ? NSLocalizedString(description, nil) : NSLocalizedString(@"Downloading", nil))
                                                message:nil
                                               delegate:nil 
                                      cancelButtonTitle:nil
                                      otherButtonTitles:nil];

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    indicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin  | 
                                  UIViewAutoresizingFlexibleRightMargin | 
                                  UIViewAutoresizingFlexibleTopMargin   | 
                                  UIViewAutoresizingFlexibleBottomMargin);

    [indicator startAnimating];
    [uistatusDialog addSubview: indicator];
    [uistatusDialog show];
    [indicator release];

And here are screenshots for both simulators:iOS 5: correct iOS 5: correct iOS 4.3: misaligned iOS 4.3: misaligned

Similar things are happening with labels for which I set frames through [UILabel alloc]initWithFrame:CGRectMake(...].

This code, for instance:

UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                                   reuseIdentifier:reuseIndentifier] autorelease];

  cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  cell.selectionStyle = UITableViewCellSelectionStyleGray;

  UILabel* mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(70, 0, 0, 20)] autorelease];
  mainLabel.font = [UIFont boldSystemFontOfSize:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 18 : 12)];
  mainLabel.textAlignment = UITextAlignmentLeft;
  mainLabel.textColor = [UIColor blackColor];
  mainLabel.backgroundColor = [UIColor clearColor];
  mainLabel.autoresizingMask = (UIViewAutoresizingFlexibleHeight | 
                                UIViewAutoresizingFlexibleWidth  | 
                                UIViewAutoresizingFlexibleRightMargin);
  //mainLabel.adjustsFontSizeToFitWidth = YES;
  mainLabel.tag = MAINLABEL_TAG;

Aligns just fine in iOS5, both for the simulators and devices. But in 4.3 it doesn't. I can only think that the local coordinate frame changed from one SDK to the next?

Any help is greatly appreciated!

EDIT: Just to pull it off for now, I did end up replacing all instances of CGRectMake(x,y,w,h) with something along the lines of (assuming x,y,w,h are the ones I would have used for CGRectMake):

CGrect refFrame = superview.frame;
refFrame.origin.x += x;
refFrame.origin.y += y;
refFrame.size.w = w;
refFrame.size.h = h;
theObjInQuestion.frame = refFrame;

So essentially, looks like a different frame of reference is being used between SDK 5 and 4.3 at least...

like image 975
SaldaVonSchwartz Avatar asked Nov 04 '22 11:11

SaldaVonSchwartz


1 Answers

I had a similar issue with one UIImageView in our app being displaced downwards about 100pts on screen, appearing to be displaced by other content that should have been floating on top of the UIImageView (though that may have been a coincidence).

The 'solution' I found in our case was to disable auto-sizing for the top positioning attribute for the UIImageView in IB, by clicking on the red I in the Autosizing display on the Size Inspector in Interface Builder. I call this a 'solution' rather than a solution because it remains unclear to me why this was a problem at all, and why this only occurred for this one view and only in iOS 5.

I also found that repositioning this view up, or down, prevented it from being displaced. It was only when it was aligned with the top edge of its parent view that the issue occurred.

My conclusion was it was probably a bug in iOS 5, rather than a new intended or more strict behavior, but I remain uncertain.

like image 125
Duncan Babbage Avatar answered Nov 09 '22 11:11

Duncan Babbage