我最近注意到我的应用程序中有一个非常奇怪的行为。为视图设置框架时,它的行为就好像原点是我输入的两倍。其他视图不受影响,受影响视图的宽度和高度也不受影响。有人以前见过或听说过这样的事情吗?
编辑:
这是我的自定义 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;
}