iPad UIViewController loads as portrait when device is in landscape
I have an application with 3 view controllers. They are all have shouldAutoRotateToInterfaceOrientation returning YES. The first two,开发者_JAVA技巧 my main menu and my submenu both autorotate just fine. The third viewcontroller, which programatically loads a UIImageView from a jpg file in the program's bundle, will only display in portrait.
In the viewcontroller containing the image, i have this:
NSString *imageName = [NSString stringWithFormat:@"%@-00%d.jpg",setPrefix,imageNumber];
UIImageView *pictureView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
pictureView.frame = CGRectMake(0, 0, 1024, 768);
[self.view addSubview:pictureView];
and again, I have shouldAutoRotateToInterfaceOrientation returning YES for all orientations.
My image shows up, but is sideways, and the 0,0,1024,768 values I used to make my rectangle start from the top right corner going down, instead of starting at the top left and going across (holding in landscape). Am I missing a parameter I need to set in order to ensure the imageview shows up in landscape instead of portrait?
I don't know for sure, but I suspect the setting of pictureView.frame
may not be correct. The frame can be "weird" (technical term) when adding a subview to an autorotated view. See Automatically Sizing UIView after Adding to Window.
精彩评论