2011-02-03 50 views
1

我最近注意到我的应用程序中有一个非常奇怪的行为。为视图设置框架时,它的行为就像是我输入的原点的两倍。没有其他视图受到影响,受影响视图的宽度和高度也不受影响。有人看过或听说过这样的事情吗?iPad像素倍增?

编辑:

这是我的自定义init方法,这似乎是不知何故导致问题的代码,但我不能挑开原因。

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; 
} 
+0

你可以张贴一些代码? – 2011-02-03 03:39:20

+0

我在发布一些代码后更新了我的答案。 – 2011-02-03 18:09:25

回答

2

我以前用xib经历过这样奇怪的事情。它通常是由xib内部被标记为iPhone xib而不是iPad xib引起的。通常它需要我从头开始重新创建xib。

这是一个通用的应用程序吗?确保您的iPad xib是您的视图控制器初始化时正在加载的那个。你添加的代码

编辑后:

的问题似乎是框架要传递中如果你的init方法获得通过的框架(10,10,W,H),然后。当你创建centerView时,意味着它将在10,10范围内,所以如果你的封闭视图在10,10和centerview在10,10的内部视图内,centerview将会出现在20,20以内的范围较大。

你想与0,0作为X,Y创建CENTERVIEW:

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