我正在尝试为iPhone 6和iPhone 6 Plus优化我的SpriteKit应用程序,但iAd横幅位置错误,我无法更改它。它适用于4英寸或3.5英寸iPhone,但在iPhone 6和6 Plus上,横幅不在底部,它略高于它。
另外,我一直在谷歌搜索这个问题。有很多解决方案,但没有一个适合我。
我在ViewController.m文件中使用以下代码作为iAd横幅:
//iAd
#pragma mark iAd Delegate Methods
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat height = CGRectGetHeight(screen);
banner.frame = CGRectOffset(banner.frame, 0, height-banner.frame.size.height);
//Changing the Y-position doesn't change the banner's position
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
if([[NSUserDefaults standardUserDefaults] boolForKey:@"Ads_savedata"] == NO)
[banner setAlpha:0];
else
[banner setAlpha:1];
[banner updateConstraints];
[UIView commitAnimations];
}
- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
对我来说,看起来以下行不会影响横幅的位置。
banner.frame = CGRectOffset(banner.frame, 0, height-banner.frame.size.height);
我希望有人可以帮我解决这个问题。谢谢你的关注。
答案 0 :(得分:0)
我猜它的屏幕宽度和高度问题。尝试一次
float SW;
float SH;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (( [[[UIDevice currentDevice] systemVersion] floatValue]<8) && UIInterfaceOrientationIsLandscape(orientation))
{
SW = [[UIScreen mainScreen] bounds].size.height;
SH = [[UIScreen mainScreen] bounds].size.width;
}
else
{
SW = [[UIScreen mainScreen] bounds].size.width;
SH = [[UIScreen mainScreen] bounds].size.height;
}