开发者

My view is displaying y=-20 dispite its frame set to y=0. After rotation it snaps back to y=0

I started by creating a universal window based app. Starting with the iPhone version I created a UIViewController and associated nib.

My App delegate:

rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[window makeKeyAndVisible];
[window addSubview:rootViewController.view];
return YES;

My RootViewController:

- (void)viewDidLoad {
[super viewDidLoad];
adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero()];
[self.view addSubview:adBannerView];

}

I've tried instanciating buttons instead of the adBanner and I get 开发者_Go百科the same result.

My RootViewController's nib has not been changed since x-code created it for me. My MainWindow_iPhone.xib also is stock.

What's causing this?

Update

After changing the app's orientation the adBannerView (or button...) will snap into the correct place at y=0. I've tried setting adBannerView's y location to 20 presumably to compensate for the status bar and that makes everything display correctly until I change orientation. Then everything moves down 20 pixels and will leave a 20 pixel space between the adBannerView and the status bar.


Try to add the next line in your viewDidLoad (right after [super viewDidLoad];):

self.view.frame = [[UIScreen mainScreen] applicationFrame];


CGRectZero is literally a zero rect (0, 0, 0, 0), so ADBannerView should never show up if it really has a width and height of 0. You probably want to try initWithFrame:self.view.frame or so…


You should set the size identifier before adding the view:

- (void)viewDidLoad {
[super viewDidLoad];
adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero()];

if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
    adBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
else
    adBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;


[self.view addSubview:adBannerView];

// now you can treat it like any other subview
// For example, if you want to move it to the bottom of the view, do this:

CGRect frame = adBannerView.frame;
frame.origin.y = self.view.frame.size.height - frame.size.height;
[adBannerView setFrame:frame];

}

Whenever the interface rotates, you should notify the banner to change its size.

Assuming you have access to WWDC videos (which is available for free), check video session 305. It demos adding the banner.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜