iOS7自动布局,查看调整大小和网络成瘾者 [英] iOS7 Auto Layout, View Resize and iAds

查看:131
本文介绍了iOS7自动布局,查看调整大小和网络成瘾者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iOS使用自动布局7项目具有以下视图层次

I'm using Auto Layout in my iOS 7 project with the following view hierarchy

主要查看结果
-container查看结果
---巴顿结果
---巴顿结果
--- ImageView的结果
-Banner查看(IAD横幅视图)

Main View
-Container View
---Button
---Button
---ImageView
-Banner View (iAd Banner View)

主视图和容器视图是全宽度和屏幕的高度。我对容器视图水平和垂直空间约束坚持主视图(屏幕的高度和宽度)。而且集装箱查看子视图被限制使用20像素的空间视图的按钮。

The Main View and Container View are full width and height of screen. I have Horizontal and Vertical Space Constraints on the Container View sticking to the main view (screen's height and width). And also the subviews of Container View are constrained to the button of the view with a 20px space.

在横幅画面终于填充并放置在屏幕的底部,然后我有容器视图减去横幅视图的从它的框架高度高度,以便横幅画面显示空间出现我的问题。 (code以下使用)的理想的结果是容器视图减去高度和它的子视图在此基础上新的高度约束的更新,但是落得发生的事情是IAD的横幅视图只是覆盖在显示在图片视图。

My issue occurs when the Banner View is finally filled and placed at the bottom of the screen, which then I have the Container View subtract the Banner View's Height from its frame height to allow space for the Banner View to show. (code used below) The ideal outcome is the Container View to subtract the height and its subviews constraint update based on this new height ,but what end up happening is the iAD Banner View just overlays the view as shown in the picture.

code为BannerViewDidLoadAd:

Code for BannerViewDidLoadAd:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    CGRect contentFrame = self.containerView.bounds;

    CGRect bannerFrame = self.bannerView.bounds;
    if (self.bannerView.bannerLoaded) {
        contentFrame.size.height = self.containerView.frame.size.height - self.bannerView.frame.size.height;

        bannerFrame.origin.y = contentFrame.size.height;;
    } else {
        bannerFrame.origin.y = contentFrame.size.height;
    }



    [UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
        [self.containerView setFrame:contentFrame];
        [self.containerView layoutIfNeeded];
        self.bannerView.frame = bannerFrame;
        self.bannerView.hidden = NO;
    }];

    [self.containerView updateConstraints];
}

iAd的图像覆盖容器视图和它的子视图

Image of iAd overlaying Container View and it's SubViews

推荐答案

在创建code横幅画面(并将其添加为主视图的子视图)后,您应添加之间的长度为0间隔约束容器视图底部和横幅广告视图(横幅画面需要约束,主视图和高度约束双方也一样)的顶部。容器视图应该有0长度的限制到主视图的所有四个边。你应该做一个IBOutlet到底层约束,并相等于横幅视图的高度(动态显示约束的恒定值,因此会缩小​​,横幅画面会随之向上移动,由于其长度为0的垂直间距约束)。因此,如果出口在底部约束被称为bottomCon和横幅视图的高度是100点,你会动画是这样的:

After you create the banner view in code (and add it as a subview of main view), you should add a 0 length spacing constraint between the bottom of the container view, and the top of the banner view (the banner view would need constraints to the two sides of the main view and a height constraint as well). The container view should have 0 length constraints to all four edges of the main view. You should make an IBOutlet to that bottom constraint, and animate that constraint's constant value by an amount equal to the height of the banner view (so it will shrink, and the banner view will move up with it due to its 0 length vertical spacing constraint). So, if the outlet to the bottom constraint was called bottomCon, and the height of the banner view was 100 points, you would animate like this:

[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
        self.bottomCon.constant = 100;
        [self.mainView layoutIfNeeded];
    }];

有没有必要隐藏和取消隐藏的看法,因为你将首先把它关闭屏幕底部反正。另外,还要确保你调用 [bannerView setTranslatesAutoresizingMaskIntoConstraints:NO]。在创建后立即横幅画面,或当你运行应用程序,你会得到自动排版错误。

There's no need to hide and unhide the view, since you will initially place it off the bottom of the screen anyway. Also make sure that you call [bannerView setTranslatesAutoresizingMaskIntoConstraints:NO] right after you create the banner view, or you'll get auto layout errors when you run the app.

这篇关于iOS7自动布局,查看调整大小和网络成瘾者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆