【问题标题】:iOS return landscape orientation when is PortraitiOS在纵向时返回横向
【发布时间】:2012-02-20 18:25:32
【问题描述】:

我正在尝试从横向或纵向开始时控制 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];
}

【问题讨论】:

    标签: objective-c ios xcode cocoa-touch iad


    【解决方案1】:

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

    关于为什么orientation不起作用,请注意the docs

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        • 1970-01-01
        相关资源
        最近更新 更多