0

我创建了一个工具栏。像这样:

    UIToolbar *toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, toolBarHeight)];

    toolbar.autoresizingMask=UIViewAutoresizingFlexibleWidth;
    UIBarButtonItem *itemNull=[[[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease];
    UIBarButtonItem *item0=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(pre)] autorelease];
    UIBarButtonItem *item1=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(pre)] autorelease];
    UIBarButtonItem *item2=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(pre)] autorelease];
    UIBarButtonItem *item3=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(pre)] 
        autorelease];
    UIBarButtonItem *item4=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(pre)] autorelease];
    itemNull.width=frame.size.width-itemwidth*5;
    item0.width=itemwidth;
    item1.width=itemwidth;
    item3.width=itemwidth;
    item4.width=itemwidth;
    item2.width=itemwidth;

    [toolbar setItems:[NSArray arrayWithObjects: itemNull,item0,item1,item2,item3,item4, nil]];
    [self addSubview:toolbar];
    [toolbar release];

它被添加到视图中。但是当我旋转视图时,这些项目不在标志上。我想知道如何让它可见而不是重置它的框架。这些项目是否具有自动调整大小之类的属性?

4

1 回答 1

0

有一个内置的隐藏工具栏..

[self.navigationController setToolbarHidden:NO animated:YES]; // i hope its a navigation based application.

修改代码

UIBarButtonItem *itemNull=[[[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease];
UIBarButtonItem *item0=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(pre)] autorelease];
UIBarButtonItem *item1=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(pre)] autorelease];
UIBarButtonItem *item2=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(pre)] autorelease];
UIBarButtonItem *item3=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(pre)] 
    autorelease];
UIBarButtonItem *item4=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(pre)] autorelease];
[self.navigationController setToolbarHidden:NO animated:YES];
self.toolbarItems = [NSArray arrayWithObjects: itemNull, item0, item1, item2, item3, item4, nil];

希望能帮助到你。快乐编码:)

于 2012-05-09T06:44:57.247 回答