iOS 在纵向时返回横向
我试图在从横向或纵向开始时控制 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您几乎总是想在这里使用
[self interfaceOrientation]
。关于为什么方向不起作用,请注意文档:
You almost always want to use
[self interfaceOrientation]
here.Regarding why
orientation
doesn't work, note the docs:你确定它告诉你它在陆地上还是根本就不是肖像,因为你设置为只识别肖像。模拟器可能返回 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?