UIViewController 中 view.frame.size.height 的变化

发布于 2024-09-24 17:34:38 字数 1604 浏览 1 评论 0原文

在我的视图中,我有一个表格和一个广告横幅,所有这些都是通过 Interface Builder 创建的。但我注意到我的 view.frame.size.height 似乎在我的应用程序执行过程中发生了变化,即使我没有更改大小。

有人可以向我解释为什么会发生这种情况吗?

我正在做的是在 viewDidLoad 上将广告横幅移出屏幕,此时,如果我打印出 self.view.frame.size.height,则该值为:460.00。此时,我还增加了 tableView 的大小,以便它占用 adBanner 曾经占用的空间,同时将 adBanner 移出屏幕。

然后当我收到bannerViewDidLoadAd消息时,我再次打印出self.view.frame.size.height,此时它是367.00。我不明白为什么视图的大小发生了变化。

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

    CGRect originalTableFrame = self.tableView.frame;
    CGFloat newTableHeight = 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];  
}

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 newTableHeight = 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];  
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2024-10-01 17:34:38

你用什么方法来隐藏横幅。如果您没有使用removeFromSuperview:,那么当您调整父视图的大小时,视图将自动调整大小(这可能会自动发生以使视图适合屏幕等)。

我建议在 Interface Builder 中(在 Inspector 的 Size 选项卡上)调整视图的自动调整大小选项,直到找到可行的东西。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文