iOS 在纵向时返回横向

发布于 2025-01-07 13:54:29 字数 701 浏览 0 评论 0原文

我试图在从横向或纵向开始时控制 iAd 大小。问题是,当设备处于纵向时,设备却显示处于横向!怎么处理呢?谢谢

- (void)viewDidLoad
{

    //iAd

    adView =[[ADBannerView alloc] initWithFrame:CGRectZero];

    adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

    adView.delegate = self;

    if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

    [self.view addSubview:adView];

    [super viewDidLoad];
}

I am trying to control iAd size when starts from landscape or portrait. Problem is that device tells that is on landscape when is on portrait! How to handle it? Thank you

- (void)viewDidLoad
{

    //iAd

    adView =[[ADBannerView alloc] initWithFrame:CGRectZero];

    adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

    adView.delegate = self;

    if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

    [self.view addSubview:adView];

    [super viewDidLoad];
}

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

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

发布评论

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

评论(2

雪化雨蝶 2025-01-14 13:54:29

您几乎总是想在这里使用[self interfaceOrientation]

关于为什么方向不起作用,请注意文档

除非通过调用 beginGenerateDeviceOrientationNotifications 启用方向通知,否则此属性的值始终返回 0。

You almost always want to use [self interfaceOrientation] here.

Regarding why orientation doesn't work, note the docs:

The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications.

给妤﹃绝世温柔 2025-01-14 13:54:29

你确定它告诉你它在陆地上还是根本就不是肖像,因为你设置为只识别肖像。模拟器可能返回 nil,如该线程中所述:UIDevice currentDevice's“orientation”始终为 null
您使用的是模拟器还是设备?

Are you sure it's telling you it's on landspace or simply not Portrait, as you if is setup to only recognize Portrait. It's possible that the simulator is returning nil, as mentioned in this thread: UIDevice currentDevice's "orientation" always null
Are you using the simulator or a device?

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