我今天安装了 4.2 iphone sdk 并使用 4.2 运行了我的项目(用 4.0 编写)。我注意到工具栏项目错位在工具栏上,无论是在 ipad、iphone 模拟器中。除了我还有其他人遇到过这种情况吗?这是代码:
@define TOOLBAR_HEIGHT 34
@define TOOLBAR_ITEM_WIDTH 90
// extends UIView
@implementation MapViewControllerContainer
- (void) setFrame:(CGRect)frame
{
[super setFrame:frame];
if (self.subviews.count == 2)
{
((UIView *)[self.subviews objectAtIndex:0]).frame = CGRectMake(0, 0, frame.size.width, TOOLBAR_HEIGHT);
((UIView *)[self.subviews objectAtIndex:1]).frame = CGRectMake(0, TOOLBAR_HEIGHT, frame.size.width,
frame.size.height - TOOLBAR_HEIGHT);
}
}
@end
// extends UIViewController
@implementation MapViewController
- (void) loadView
{
self.view = [[MapViewControllerContainer alloc] init];
[self.view release];
UIToolbar * toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleBlack;
UIBarButtonItem * flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
detailsButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Details",@"")
style:UIBarButtonItemStyleBordered target:self
action:@selector(detailsPressed)];
detailsButton.width = TOOLBAR_ITEM_WIDTH;
detailsButton.enabled = NO;
toolbar.items = [NSArray arrayWithObjects: flexibleItem, detailsButton, nil];
[flexibleItem release];
[detailsButton release];
[self.view addSubview:toolbar];
[toolbar release];
// More non-related code here
}
@end
这是它的输出:
输出 http://dl.dropbox.com/u/13741164/toolbar.jpg
如您所见,详细信息按钮在右侧超出框架。TOOLBAR_ITEM_WIDTH 越小,它在框架内的越多。所以我认为工具栏项的计算存在一个错误,因为它在 4.0 sdk 中运行得非常好,对吧?谢谢你的帮助。