iOS:支持 iAds 和 iOS 的通用应用程序模板屏幕旋转

发布于 2024-10-27 01:04:51 字数 1528 浏览 6 评论 0原文

我正在尝试构建一个 iOS 通用应用程序模板,该模板可以透明地处理 iAds 和 iAds。屏幕旋转。

即,我不会为每个新项目使用 UIViewController,而是使用我自己的 iAdVC(它将子类化 UIViewController)。这将无缝处理 iAd,并将剩余的窗口空间移交给用户。

我正在尝试这个:视图控制器包含 uberView,其中包含 {adView,内容视图}。

每当广告出现和消失时,{adView, content view} 都会进行动画处理:

  • 内容视图稍微向下挤压框架的顶部,为我的 iAd 腾出空间,

  • 同时沿顶部淡入广告。

    此外,每次设备旋转时,视图的大小都需要调整。

我遇到了非常愚蠢的问题,当第一个广告投放时,我将其放置在屏幕顶部并挤压剩余的内容框架以为其腾出空间。

但如果我更改内容视图的框架,我将无法再点击广告。如果我不这样做,内容视图将不适合其窗口,

http://d.pr/ZyQG< /a>

- (void) bannerViewDidLoadAd: (ADBannerView *) banner 
{   
    bool isLandscape = UIInterfaceOrientationIsLandscape( self.interfaceOrientation );
    NSString * contentSize = isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait ;
    
    [self.adBannerView setCurrentContentSizeIdentifier: contentSize];
    
    CGSize bannerSize = [ADBannerView sizeFromBannerContentSizeIdentifier: contentSize];
    self.adBannerView.frame = CGRectMake(0, 0, bannerSize.width, bannerSize.height);
    
    // resize content frame & fade ad in        
    CGRect newContentFrame = uberView.bounds;
    newContentFrame.size.height -= bannerSize.height;
    newContentFrame.origin.y += bannerSize.height;   
    
    NSLog(@"%@", NSStringFromCGRect(newContentFrame)); // {{0, 50}, {320, 430}}
    if (1) // 0 works
        self.contentView.frame = newContentFrame; // NOW CANT CLICK AD
}

I am trying to construct a iOS universal application template that transparently handles iAds & screen rotations.

i.e. instead of using UIViewController for each new project, I will instead use my own iAdVC (which will subclass UIViewController). This will seamlessly handle the iAds, and hand over the remaining window space to the user.

I'm trying this: view controller contains uberView which contains {adView, content view}.

whenever an ad appears and disappears, both {adView, content view} will animate:

  • content view squashing the frame's top down slightly to make space for my iAd,

  • and fade in the ad along the top at the same time.

    also, every time the device rotates, the views need to be resized.

I'm getting really dumb problem, when the first Ad gets served, I place it at the top of the screen and squash the remaining content frame to make space for it.

but if I change the content view's frame, I can no longer click the ad. and if I don't, the content view doesn't fit in its window,

http://d.pr/ZyQG

- (void) bannerViewDidLoadAd: (ADBannerView *) banner 
{   
    bool isLandscape = UIInterfaceOrientationIsLandscape( self.interfaceOrientation );
    NSString * contentSize = isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait ;
    
    [self.adBannerView setCurrentContentSizeIdentifier: contentSize];
    
    CGSize bannerSize = [ADBannerView sizeFromBannerContentSizeIdentifier: contentSize];
    self.adBannerView.frame = CGRectMake(0, 0, bannerSize.width, bannerSize.height);
    
    // resize content frame & fade ad in        
    CGRect newContentFrame = uberView.bounds;
    newContentFrame.size.height -= bannerSize.height;
    newContentFrame.origin.y += bannerSize.height;   
    
    NSLog(@"%@", NSStringFromCGRect(newContentFrame)); // {{0, 50}, {320, 430}}
    if (1) // 0 works
        self.contentView.frame = newContentFrame; // NOW CANT CLICK AD
}

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

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

发布评论

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

评论(2

权谋诡计 2024-11-03 01:04:51

最低部署目标
第一个问题是:合理的最低部署目标是什么?鉴于这是一个通用应用程序,我们应该使用iOS 4.2,因为这是iPhone和iPad之间第一个统一的版本。

问题出现了:我们失去了多少点击广告的客户?例如,仅仅为了获得额外 15% 的客户是否值得支持 4.0?

http://insights。 chitika.com/2011/ios-update-ipads-iphones-running-high-rate-of-ios-4/ 显示,如果您选择 4.2,您仍会获得 80% 的广告点击客户。

显然,这个比例会随着时间的推移而增加,所以我会选择最简单的编码选项,而不是试图从市场上榨取最后一分钱。

这还有一个额外的好处:

// Supported sizes of banner ads available from ad server. Dimensions are in points, not pixels.
// The dimensions are part of the value names to assist with design-time planning for view layout.
extern NSString * const ADBannerContentSizeIdentifier320x50 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_4_0,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifier480x32 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_4_0,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifierPortrait __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifierLandscape __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_2);

即我们可以使用通用的新符号(即适用于 iPhone 和 iPad)

strPortrait = ADBannerContentSizeIdentifierPortrait; // ADBannerContentSizeIdentifier320x50;
strLandscape = ADBannerContentSizeIdentifierLandscape; // ADBannerContentSizeIdentifier480x32;

横幅可以是水平或垂直的,因此你需要加载:

[self.adBannerView setRequiredContentSizeIdentifiers:
    [NSSet setWithObjects: strPortrait, strLandscape, nil]
];  

然后当屏幕旋转90°时,需要告诉AdBannerView:

[self.adBannerView setCurrentContentSizeIdentifier: isLandscape ? strLandscape : strPortrait ];

设置后,你可以直接查询self.adBannerView.frame并获取新的尺寸

Minimum deployment target
The first question is: what is a sensible minimum deployment target? Seeing as this is a universal application, we should use iOS 4.2, as this is the first version that is unified between iPhone and iPad.

Question arises: what fraction of ad-clicking customers do we lose? eg is it worth supporting 4.0 just to get an extra 15% of customers?

http://insights.chitika.com/2011/ios-update-ipads-iphones-running-high-rate-of-ios-4/ shows that you still pick up 80% of ad-clicking customers if you select 4.2.

Obviously this fraction is going to increase with time, so I'm going for the easiest coding option rather than trying to squeeze every last penny out of the market.

This has an added benefit:

// Supported sizes of banner ads available from ad server. Dimensions are in points, not pixels.
// The dimensions are part of the value names to assist with design-time planning for view layout.
extern NSString * const ADBannerContentSizeIdentifier320x50 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_4_0,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifier480x32 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_4_0,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifierPortrait __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifierLandscape __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_2);

ie We can use the new symbols, which are generic (ie work for both iPhone and iPad)

strPortrait = ADBannerContentSizeIdentifierPortrait; // ADBannerContentSizeIdentifier320x50;
strLandscape = ADBannerContentSizeIdentifierLandscape; // ADBannerContentSizeIdentifier480x32;

The banner can be either horizontal or vertical, so you need to load in:

[self.adBannerView setRequiredContentSizeIdentifiers:
    [NSSet setWithObjects: strPortrait, strLandscape, nil]
];  

Then when the screen turns 90°, the AdBannerView needs to be told:

[self.adBannerView setCurrentContentSizeIdentifier: isLandscape ? strLandscape : strPortrait ];

Directly after this is set, you can query self.adBannerView.frame and get the new size

久伴你 2024-11-03 01:04:51

https://github.com/pi-/iAdUniversalTemplate

这是一个无 XIB 的通用应用程序iAd-rotatey-enabled 模板,要求最低目标为 iOS 4.2

它花了很多时间,即 iAd -- 无法点击横幅

但现在状态良好。

https://github.com/p-i-/iAdUniversalTemplate

This is a XIB-less universal-app iAd-rotatey-enabled template, which requires a minimum target of iOS 4.2

It took a lot of thrashing around, namely iAd -- cannot click banner

But it is in good shape now.

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