开发者

iPad Pixel Doubling?

I have 开发者_StackOverflow社区recently noticed a very strange behavior in my app. When setting the frame for a view, it behaves as if the origin is twice what I type in. No other views are affected, and neither are the width and height of the affected view. Anybody seen or heard of something like this before?

EDIT:

This is the code in my custom init method, which seems to be causing the problem somehow, but I can't pick apart why.

if ((self = [super initWithFrame:frame])) {
        self.backgroundColor = [UIColor clearColor];
        self.controller = aController;
        self.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
        UIView *centerView = [[UIView alloc] initWithFrame:frame];
        [self addSubview:centerView];
        UIToolbar *navBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 44)];
        NSMutableArray *array = [[NSMutableArray alloc] init];
        UIBarButtonItem *item = item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(closeClicked:)];
        [array addObject:item];
        item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        [array addObject:item];
        item = [[UIBarButtonItem alloc] initWithTitle:@"Title" style:UIBarButtonItemStylePlain target:nil action:nil];
        [array addObject:item];
        item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        [array addObject:item];
        item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
        [array addObject:item];
        [navBar setItems:array];
        [centerView addSubview:navBar];
        centerView.clipsToBounds = YES;
        centerView.opaque = TRUE;
        centerView.alpha = 1.0;
        centerView.backgroundColor = [UIColor whiteColor];
        [self addSubview:centerView];
    }
    return self;
}


I have experienced weird things like this before with xibs. It is usually caused by the xib internally being labeled as an iPhone xib instead of an iPad xib. Usually it requires me to recreate the xib from scratch.

Is it a universal app? Make sure your iPad xib is the one being loaded when your view controller is init'd.

EDIT after you added code:

The problem appears to be the frame that you are passing in. If your init method is getting passed a frame of (10,10,w,h), then when you create centerView that means it will be at 10,10 within whatever his context is, so if your enclosing view here is at 10,10 and the centerview is at 10,10 within the enclosing view, the centerview will appear to be at 20,20 within the larger scope.

You'll want to create your centerView with 0,0 as its x,y:

CGRect centerViewFrame = CGRectMake(0, 0, frame.size.width, frame.size.height);
UIView *centerView = [[UIView alloc] centerViewFrame];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜