Friday, August 5, 2011

Why my NIB-less projects won't auto-rotate?

Found a problem with the NIB-less projects I have created so far. For some unknown reason, it won't auto-rotate? That is, if I create a simple NIB-less project with only 1 button and 1 label, and then rotate the simulator to either direction, then even if I change the "shouldAutorotateToInterfaceOrientation" as below to always return "YES", it won't move at all?


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}


However, if I create another new project with NIB and create same button, label and same change to "shouldAutorotateToInterfaceOrientation" as above, both the button and label rotates nicely, why???

Very strange... Tried using the "nib2objc" tool to analysis the XIB file and it dumps lots of info about the view shown below, but still couldn't work out which property/attribute should be copied over to NIB-less version to make it auto-rotate... I am stuck :-( !!!


UIView *view6 = [[UIView alloc] initWithFrame:CGRectMake(0.0, 20.0, 320.0, 460.0)];
view6.frame = CGRectMake(0.0, 20.0, 320.0, 460.0);
view6.alpha = 1.000;
view6.alphaValue = // unknown property: 1;
view6.autoresizesSubviews = YES;
view6.autoresizesSubviewsForDevice = // unknown property: 1;
view6.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view6.backgroundColor = [UIColor colorWithWhite:0.750 alpha:1.000];
view6.backgroundFilters = // unknown property: (
);
view6.canDrawConcurrently = // unknown property: 0;
view6.clearsContextBeforeDrawing = NO;
view6.clipsSubviews = // unknown property: 0;
view6.clipsToBounds = NO;
view6.contentFilters = // unknown property: (
);
view6.contentMode = UIViewContentModeScaleToFill;
view6.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}");
view6.focusRingType = // unknown property: 0;
view6.frameCenterRotation = // unknown property: 0;
view6.frameOrigin = // unknown property: {0, 20};
view6.frameSize = // unknown property: {320, 460};
view6.hidden = NO;
view6.ibExternalIdentityShowNotesWithSelection = // unknown property: 0;
view6.multipleTouchEnabled = NO;
view6.opaque = YES;
view6.opaqueForDevice = // unknown property: 1;
view6.simulatedOrientationMetrics = // unknown property: [This value is not printable by ibtool (IBUISimulatedOrientationMetrics)];
view6.simulatedStatusBarMetrics = // unknown property: [This value is not printable by ibtool (IBUISimulatedStatusBarMetrics)];
view6.tag = 0;
view6.userInteractionEnabled = YES;
view6.wantsLayer = // unknown property: 0;


0 comments:

Post a Comment