开发者

view.frame.size.height changing in UIViewController

Inside my view, I have a table and an ad banner, all of which are created through Interface Builder. But I noticed that my view.frame.size.height seems to change through the course of execution of my app even though I haven't changed the size.

Can someone explain to me why this is happening?

What I'm doing is moving the ad banner off screen on viewDidLoad, at which point, if I print out self.view.frame.size.height, the value is: 460.00. At this time, I am also increasing the tableView's size so it takes up the space the adBanner once occupied and moving the adBanner off-screen at the same time.

Then later on when I get the bannerViewDidLoadAd message, I once again print out the self.view.frame.size.height, at which point it is 367.00. I don't understand why the view's size has changed.

- (void)moveAdvertOffScreen
{
    // Make the table view take up the void left by the banner (320x50 block)

    CGRect originalTableFrame = self.tableView.frame;
    CGFloat newTa开发者_开发技巧bleHeight = self.view.frame.size.height;

    CGRect newTableFrame = originalTableFrame;
    newTableFrame.size.height = newTableHeight;

    // Position the banner below the table view (offscreen)
    CGRect newBannerFrame = self.adBannerView.frame;
    newBannerFrame.origin.y = newTableHeight;

    self.tableView.frame = newTableFrame;   
    self.adBannerView.frame = newBannerFrame;    
}

- (void)moveAdvertOnScreen
{
    CGRect newBannerFrame = self.adBannerView.frame;    
    newBannerFrame.origin.y = self.view.frame.size.height - newBannerFrame.size.height;

    CGRect originalTableFrame = self.tableView.frame;
    CGFloat newTableHeight = self.view.frame.size.height - newBannerFrame.size.height;

    CGRect newTableFrame = originalTableFrame;
    newTableFrame.size.height = newTableHeight;

    [UIView beginAnimations:@"BannerViewIntro" context:NULL];
    self.tableView.frame = newTableFrame;
    self.adBannerView.frame = newBannerFrame;
    [UIView commitAnimations];  
}


What method are you using to hide the banner. If you aren't using removeFromSuperview: then the view is going to get autoresized when you resize the parent view (which may in turn happen automatically to fit the view to the screen, etc).

I'd suggest having a fiddle with the autoresize options for the view within Interface Builder (on the Size tab of the Inspector) until you find something that works.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜