开发者

Nested UIView Resizing

I'm developing my first iPad application, and the app is 开发者_运维百科a split view like the mail app. Inside the detail view I have 2 sub views, one for editing data and one for just viewing data. When the user is in the view mode they press a button and the detail view flips over to reveal the edit view.

I can't seem to make the two views inside the detail view resize properly with the iPad orientation change. The views are the correct size when in portrait mode, but when changed to landscape mode, the two subviews clip at the bottom and right hand edges. I thought these views were supposed to resize automatically with the view they are nested inside.

In the root view controller, I have the following code:

@implementation RootViewController

@synthesize detailViewController;
@synthesize recipies= recipies;
@synthesize delegate;

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
    self.clearsSelectionOnViewWillAppear = NO;
    self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
    self.detailViewController.recipeView.autoresizingMask=  (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth );
    self.detailViewController.isEdit= FALSE;
    self.detailViewController.editView.autoresizingMask=  (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth );
    self.detailViewController.editView.hidden=  YES;

}

The subviews that should resize are recipeView and editView. I thought by setting the autoresizeingMask, they would automatically resize. What am I missing here, do I need to explicitly set the size of each view based on the available space on orientation change?

Any/All replies appreciated! Thanks in advance.


Did you ever find an answer to your question. I am in a similar or exact same position as you. I have a the detailview and then insert subviews at index 0 onto the detailview but the sizes are all wrong and I cannot work out why.

If I add the detailview and a subview at the same time (ie add the detailview to the splitviewcontrollers array of views) then the sizes are correct, but if i simple insert a subview onto the already existing detailview then the size either works in Portrait and not in landscape or vica versa (ie I think the autoresize does not work). My solution is after initiating a view to be inserted I check orientation and force its size. eg

if ( (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) )
        {

            self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, 703, 724); 
        }
        // CHECK:   PORTRAIT
        else
        {
            self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, 768, 980); 
        }   

My sizings are obviously specific to what toolbars or tabbars I have on the detailview underneath which is why I have the strange sizes.

In my limited opinion and understanding of iOS sdk my solution above is a hack at best, iOS should be doing this for us and there must be something we are doing wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜