Iphone 网络成瘾景观奇怪的视图行为
我有一个iAd,它显示在主视图的全屏子视图的顶部。iAd在纵向模式下正常工作,我已经将iAd横幅视图旋转到横向模式。当用户在横向模式下点击iAd时,会出现此问题。测试广告以纵向、横向方式显示在手机上,当用户点击x以关闭iAd时,横幅视图及其父视图将被推到屏幕外。iAd在纵向模式下正常运行(即点击并关闭它会导致包含横幅的视图正常显示) 我尝试过的事情:Iphone 网络成瘾景观奇怪的视图行为,iphone,ios,iad,Iphone,Ios,Iad,我有一个iAd,它显示在主视图的全屏子视图的顶部。iAd在纵向模式下正常工作,我已经将iAd横幅视图旋转到横向模式。当用户在横向模式下点击iAd时,会出现此问题。测试广告以纵向、横向方式显示在手机上,当用户点击x以关闭iAd时,横幅视图及其父视图将被推到屏幕外。iAd在纵向模式下正常运行(即点击并关闭它会导致包含横幅的视图正常显示) 我尝试过的事情: - (void)bannerViewActionDidFinish:(ADBannerView *)banner{ NSLog(@"Ad was
- (void)bannerViewActionDidFinish:(ADBannerView *)banner{
NSLog(@"Ad was closed, show the adView again");
if(UIInterfaceOrientationIsLandscape(currentInterfaceOrientation)){
[self animateRotationToLandscape:0.3f];
}
else{
[self animateRotationToPortrait:0.3f];
}
}
-(void)animateRotationToPortrait:(NSTimeInterval)duration{
self.adView.currentContentSizeIdentifier =
ADBannerContentSizeIdentifierPortrait;
BOOL iPad = NO;
#ifdef UI_USER_INTERFACE_IDIOM
iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#endif
if (iPad) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
proUpgradeDescription.frame = CGRectMake(82,313,604,110);
proUpgradePrice.frame = CGRectMake(313,576,142,28);
closeButton.frame = CGRectMake(348,834,72,37);
purchaseButton.frame = CGRectMake(313,431,142,142);
[UIView commitAnimations];
}
else{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
proUpgradeDescription.frame = CGRectMake(20,80,280,70);
proUpgradePrice.frame = CGRectMake(88,322,142,28);
closeButton.frame = CGRectMake(123,403,72,37);
purchaseButton.frame = CGRectMake(88,172,142,142);
[UIView commitAnimations];
}
}
这调用了我用来为纵向和横向模式的显示旋转设置动画的代码。此代码无效
如果有人知道为什么测试广告不能正确旋转,以及为什么他们将父视图控制器从屏幕上推下,我将不胜感激。我不知道这是否解决了您的所有问题,但根据上的答案,测试广告只是纵向的,真正的广告会出现在两个方向上。我知道这个问题有点老了,所以我在这里发帖,以防有人遇到同样的问题(我曾经问过) ADBannerView会弄乱父视图的帧和变换属性,因此您只需在完成后将它们重置为原始值即可(在
bannerViewActionDidFinish:
)
我仍然不明白为什么它没有把所有的事情都恢复到它完成后的样子。我们不应该这样做。这也让我发疯了。只在iPad上发布横向整版广告,在iPhone上发布纵向广告,而不这么说是自找麻烦。我放弃了使用iAdSuite代码,这导致了横向iPad广告在屏幕上留下横向效果,即使设备是纵向的 这是我的横幅广告代码。它是所有在第一个视图控制器加载。它的目的是把横幅放在屏幕的底部 在头文件中:
#import "iAd/ADBannerView.h"
@property (strong, nonatomic) ADBannerView* adView;
@interface myViewController : UIViewController <ADBannerViewDelegate,
然后
然后,为了处理来自iAd的回调,我们需要告诉视图,如果某些内容发生更改,则重新进行布局:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView animateWithDuration:0.25 animations:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView animateWithDuration:0.25 animations:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];}
这似乎可以正确处理iPad和iPhone上的方向,但测试整版广告除外。但是,在测试广告被取消后,屏幕呈现出正确的方向,因此我希望一切正常。那么你认为我应该将应用程序提交到app store,并希望这不是部署版本的问题?在提交应用商店之前,我无法测试iAd。@wasabi您提交了应用吗?他们接受了吗?从app store下载时,您的广告是否正确显示?@Rookie yes接受的答案是正确的。应用商店中的横向广告效果良好。我最终删除了IAD,因为它们干扰了用户体验。@wasabi谢谢你回复我。非常感谢您的AnimateRotationLandscape代码在哪里?@wasabi您提交了应用程序吗?他们接受了吗?从app store下载时,您的广告是否正确显示?在viewDidLoad的代码中,您在调用[adView sizeThatFits:contentFrame.size]后正在初始化adView。此时adView不是nil吗?self.adView=[[ADBannerView alloc]initWithAdType:ADAdTypeBanner];[self.view addSubview:self.adView];CGRect contentFrame=self.view.bounds;CGRect bannerFrame=CGRectZero;bannerFrame.size=[self.adView sizehattfits:contentFrame.size];bannerFrame.origin.y=contentFrame.size.height-bannerFrame.size.height;[self.adView setFrame:bannerFrame];抱歉耽搁了!我认为adView虽然没有内容,但它是AdBannerView,因此返回一个大小。这似乎是可行的,我会在某个时候运行调试器来看看它在做什么。你能提供更多的上下文吗?怎么把它放回去?
-(void)viewWillLayoutSubviews {
CGRect contentFrame = self.view.bounds;
CGRect bannerFrame=CGRectZero;
bannerFrame.size = [adView sizeThatFits:contentFrame.size];
if (adView.bannerLoaded) {bannerFrame.origin.y = contentFrame.size.height-bannerFrame.size.height;}
else {bannerFrame.origin.y = contentFrame.size.height;}
[adView setFrame:bannerFrame];}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView animateWithDuration:0.25 animations:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView animateWithDuration:0.25 animations:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];}